use textport

git-svn-id: svn://qnap.local/TwoTerm/trunk@2024 5590a31f-7b70-45f8-8c82-aa3a8e5f4507
This commit is contained in:
Kelvin Sherlock 2011-02-06 18:32:27 +00:00
parent 272ad2a166
commit 46ebda708c
2 changed files with 60 additions and 21 deletions

View File

@ -11,6 +11,9 @@
#import "Emulator.h" #import "Emulator.h"
#include "iGeometry.h" #include "iGeometry.h"
#ifdef __cplusplus
#include "Screen.h"
#endif
@interface PTSE : NSObject <Emulator> @interface PTSE : NSObject <Emulator>
{ {
@ -18,6 +21,10 @@
iPoint _dca; iPoint _dca;
uint8_t _repeatChar; uint8_t _repeatChar;
#ifdef __cplusplus
TextPort _textPort;
#endif
} }

View File

@ -53,10 +53,34 @@ enum {
return "proterm-special"; return "proterm-special";
} }
-(void)reset: (Screen *)screen
{
[self reset];
if (screen)
{
screen->setFlag(Screen::FlagNormal);
screen->setTextPort(_textPort);
screen->erase(Screen::EraseAll);
}
}
-(void)reset -(void)reset
{ {
struct winsize ws = [self defaultSize];
_state = StateText; _state = StateText;
_textPort.cursor = iPoint(0, 0);
_textPort.frame = iRect(0, 0, ws.ws_col, ws.ws_row);
_textPort.scroll = true;
_textPort.advanceCursor = true;
_textPort.clampX = true;
_textPort.clampY = true;
_textPort.leftMargin = TextPort::MarginWrap;
_textPort.rightMargin = TextPort::MarginWrap;
} }
-(BOOL)resizable -(BOOL)resizable
@ -71,6 +95,11 @@ enum {
return ws; return ws;
} }
-(id)init
{
[self reset];
return self;
}
-(void)initTerm: (struct termios *)term -(void)initTerm: (struct termios *)term
{ {
@ -101,36 +130,36 @@ enum {
case CTRL('H'): case CTRL('H'):
//Move cursor left one character. //Move cursor left one character.
screen->decrementX(); screen->decrementX(&_textPort);
break; break;
case CTRL('U'): case CTRL('U'):
//Move cursor right one character. //Move cursor right one character.
screen->incrementX(); screen->incrementX(&_textPort);
break; break;
case CTRL('K'): case CTRL('K'):
//Move cursor up one line. //Move cursor up one line.
screen->decrementY(); screen->decrementY(&_textPort);
break; break;
case CTRL('J'): case CTRL('J'):
//Move cursor down one line. //Move cursor down one line.
//screen->incrementY(); //screen->incrementY();
screen->lineFeed(); screen->lineFeed(&_textPort);
break; break;
case CTRL('I'): case CTRL('I'):
//Move cursor to next tab stop (every 8 chars). //Move cursor to next tab stop (every 8 chars).
screen->tabTo((screen->x() + 8) & ~0x07); screen->tabTo(&_textPort, (_textPort.cursor.x + 8) & ~0x07);
break; break;
case CTRL('A'): case CTRL('A'):
//Move cursor to beginning of line. //Move cursor to beginning of line.
screen->setX(0); screen->setX(&_textPort, 0);
break; break;
case CTRL('B'): case CTRL('B'):
//Move cursor to end of line. //Move cursor to end of line.
screen->setX(screen->width() - 1); screen->setX(&_textPort, _textPort.frame.width() - 1);
break; break;
case CTRL('X'): case CTRL('X'):
//Move cursor to upper-left corner. //Move cursor to upper-left corner.
screen->setCursor(0, 0); screen->setCursor(&_textPort, 0, 0);
break; break;
case CTRL('^'): case CTRL('^'):
// CONTROL-^, X + 32, Y + 32 // CONTROL-^, X + 32, Y + 32
@ -140,43 +169,46 @@ enum {
case CTRL('M'): case CTRL('M'):
//screen->lineFeed(); //screen->lineFeed();
screen->setX(0); screen->setX(&_textPort, 0);
break; break;
case CTRL('D'): case CTRL('D'):
//Delete current character (under cursor). //Delete current character (under cursor).
// TODO -- does this shift the rest of the row? // TODO -- does this shift the rest of the row? Assuming yes.
screen->deletec(); screen->deletec(&_textPort);
break; break;
case CTRL('F'): case CTRL('F'):
//Insert space at cursor. //Insert space at cursor.
screen->insertc(' '); // TODO -- does this wrap? Assuming no.
screen->insertc(&_textPort, ' ');
break; break;
case CTRL('Z'): case CTRL('Z'):
//Delete current line. //Delete current line.
screen->deleteLine(screen->y()); // TODO -- textPort
screen->deleteLine(&_textPort, _textPort.cursor.y);
break; break;
case CTRL('V'): case CTRL('V'):
//Insert blank like. //Insert blank like.
// TODO -- verify if the line is before or after the current line, // TODO -- verify if the line is before or after the current line,
// TODO -- verify if x/y change // TODO -- verify if x/y change
// TODO -- verify scrolling behavior. // TODO -- verify scrolling behavior.
screen->insertLine(screen->y()); // TODO -- textPort
screen->insertLine(&_textPort, _textPort.cursor.y);
break; break;
case CTRL('Y'): case CTRL('Y'):
//Clear to end of line. //Clear to end of line.
screen->eraseLine(); screen->erase(&_textPort, Screen::EraseLineAfterCursor);
break; break;
case CTRL('W'): case CTRL('W'):
//Clear to end of screen. //Clear to end of screen.
screen->eraseScreen(); screen->erase(&_textPort, Screen::EraseAfterCursor);
break; break;
case CTRL('L'): case CTRL('L'):
//Clear the screen (and home cursor) //Clear the screen (and home cursor)
screen->setCursor(0, 0); screen->setCursor(&_textPort, 0, 0);
screen->eraseScreen(); screen->erase(&_textPort, Screen::EraseAll);
break; break;
@ -228,7 +260,7 @@ enum {
default: default:
if (c >= 0x20 && c < 0x7f) if (c >= 0x20 && c < 0x7f)
{ {
screen->putc(c); screen->putc(&_textPort, c);
} }
break; break;
@ -246,7 +278,7 @@ enum {
case StateDCAY: case StateDCAY:
_dca.y = c - 32; _dca.y = c - 32;
screen->setCursor(_dca); screen->setCursor(&_textPort, _dca);
_state = StateText; _state = StateText;
break; break;
@ -259,7 +291,7 @@ enum {
case StateRepeatCount: case StateRepeatCount:
for (unsigned i = 0; i < c; ++i) for (unsigned i = 0; i < c; ++i)
{ {
screen->putc(_repeatChar); screen->putc(&_textPort, _repeatChar);
} }
_state = StateText; _state = StateText;
break; break;