2 ** Copyright 2002, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
5 #include <sys/syscalls.h>
9 #include <newos/tty_priv.h>
16 mSem
= _kern_sem_create(1, "term lock");
19 flags
.input_flags
= TTY_FLAG_NLCR
| TTY_FLAG_CRNL
;
20 flags
.output_flags
= TTY_FLAG_NLCR
;
22 ioctl(mFd
, _TTY_IOCTL_SET_TTY_FLAGS
, &flags
, sizeof(flags
));
28 flags
.input_flags
= TTY_FLAG_DEFAULT_INPUT
;
29 flags
.output_flags
= TTY_FLAG_DEFAULT_OUTPUT
;
31 ioctl(mFd
, _TTY_IOCTL_SET_TTY_FLAGS
, &flags
, sizeof(flags
));
35 _kern_sem_delete(mSem
);
40 _kern_sem_acquire(mSem
, 1);
45 _kern_sem_release(mSem
, 1);
48 void Term::ClearScreen()
54 void Term::SaveCursor()
59 void Term::RestoreCursor()
69 ssize_t
Term::Write(const char *buf
)
71 return write(mFd
, buf
, strlen(buf
));
74 ssize_t
Term::WriteEscaped(const char *inbuf
)
79 sprintf(buf
, "%c%s", esc
, inbuf
);
84 void Term::SetScrollRegion(int y
, int height
)
88 sprintf(buf
, "[%d;%dr", y
, y
+ height
- 1);
92 void Term::SetCursor(int x
, int y
)
96 sprintf(buf
, "[%d;%dH", y
, x
);
100 void Term::ScrollUp(int count
)
104 sprintf(buf
, "[%dM", count
);
108 void Term::ScrollDown(int count
)
112 sprintf(buf
, "[%dL", count
);
116 TermWindow::TermWindow(Term
*term
, int x
, int y
, int width
, int height
)
125 TermWindow::~TermWindow()
129 void TermWindow::Clear()
134 void TermWindow::SetScrollRegion()
136 mTerm
->SetScrollRegion(mY
, mHeight
);
139 void TermWindow::ScrollUp(int count
)
146 mTerm
->SetCursor(1, mY
+ mHeight
- 1);
148 mTerm
->ScrollUp(count
);
150 mTerm
->RestoreCursor();
155 void TermWindow::ScrollDown(int count
)
162 mTerm
->SetCursor(1, mY
);
164 mTerm
->ScrollDown(count
);
166 mTerm
->RestoreCursor();
171 void TermWindow::Write(const char *buf
, bool atLastLine
)
179 mTerm
->SetCursor(1, mY
+ mHeight
- 1);
183 mTerm
->RestoreCursor();
187 void TermWindow::SetCursor(int x
, int y
)
200 mTerm
->SetCursor(mX
+ x
- 1, mY
+ y
- 1);