8 Commits
r1 ... r2

Author SHA1 Message Date
Kelvin Sherlock
8d282293f0 version bump. 2018-01-29 21:35:26 -05:00
Kelvin Sherlock
c41a520ef8 Merge branch 'master' of https://github.com/ksherlock/TwoTerm 2018-01-29 21:24:51 -05:00
Kelvin Sherlock
42b9206abe replace grand-central io/pid monitoring with a dedicated thread and kevents.
based on testing, the pty EOF is never flagged. Instead, exit the thread when the child pid dies.
2018-01-29 21:24:15 -05:00
Kelvin Sherlock
3542ed50ce fix scroll-right bug (PTSE) 2018-01-29 21:22:08 -05:00
ksherlock
b25935338e Create README.md 2018-01-27 14:43:44 -05:00
Kelvin Sherlock
6299c68117 pics 2018-01-27 14:42:24 -05:00
Kelvin Sherlock
0044693288 pics 2018-01-27 14:34:02 -05:00
Kelvin Sherlock
4f1e79178f use ragel version of gno console emulator 2018-01-27 13:26:15 -05:00
11 changed files with 129 additions and 150 deletions

View File

@@ -357,7 +357,7 @@
screen->eraseRect(tmp); screen->eraseRect(tmp);
} }
// hmmm ... embedded control characters seem to be processed as control characters... # hmmm ... embedded control characters seem to be processed as control characters...
| 0x1e arg1 arg2 ${ | 0x1e arg1 arg2 ${
// CTRL('^'): // CTRL('^'):
// goto x y // goto x y
@@ -390,9 +390,6 @@
@implementation GNOConsole @implementation GNOConsole
+(void)load +(void)load
{ {
[EmulatorManager registerClass: self]; [EmulatorManager registerClass: self];

View File

@@ -178,7 +178,7 @@ static void advance(Screen *screen, gsos_context &ctx) {
*/ */
if (cursor.y < window.maxY()-1) cursor.y++; if (cursor.y < window.maxY()-1) cursor.y++;
else if (_context.consScroll) else if (_context.consScroll)
screen->scrollUp(window); screen->scrollUp(window);
} }
| 0x0b ${ | 0x0b ${

View File

@@ -21,7 +21,7 @@
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1</string> <string>2</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string> <string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>

12
README.md Normal file
View File

@@ -0,0 +1,12 @@
# TwoTerm
Apple-II inspired terminal emulator for OS X
Uses the Apple II character generator font but also emulates the GS/OS Console, GNO/ME Console, etc.
You'll probably need a [termcap](https://github.com/ksherlock/a2-terminfo) entry.
![](screenshots/vim.png?raw=true)
![](screenshots/cal.png?raw=true)

View File

@@ -7,7 +7,7 @@
// //
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include <atomic>
@class EmulatorView; @class EmulatorView;
@class ColorView; @class ColorView;
@@ -25,11 +25,9 @@
NSObject <Emulator> *_emulator; NSObject <Emulator> *_emulator;
NSThread * _thread;
int _fd; int _fd;
pid_t _pid; std::atomic<pid_t> _pid;
dispatch_source_t _read_source;
dispatch_source_t _wait_source;
} }

View File

@@ -11,8 +11,11 @@
#import "CurveView.h" #import "CurveView.h"
#import "EmulatorWindow.h" #import "EmulatorWindow.h"
//#import "VT52.h" #include <sys/types.h>
//#import "PTSE.h" #include <sys/event.h>
#include <sys/time.h>
#include <atomic>
#import "Defaults.h" #import "Defaults.h"
@@ -48,7 +51,7 @@
[_colorView release]; [_colorView release];
[_parameters release]; [_parameters release];
[_thread release];
[super dealloc]; [super dealloc];
} }
@@ -174,143 +177,120 @@
[_emulatorView setFd: _fd]; [_emulatorView setFd: _fd];
[self monitor]; [self monitor];
}
/*
if (!_childMonitor) -(BOOL)read: (int)fd {
{
_childMonitor = [ChildMonitor new]; BOOL rv = NO;
[_childMonitor setDelegate: _emulatorView];
for(;;) {
uint8_t buffer[1024];
ssize_t size = read(fd, buffer, sizeof(buffer));
if (size < 0 && errno == EINTR) continue;
if (size <= 0) break;
[_emulatorView processData: buffer size: size];
rv = YES;
} }
*/
return rv;
}
-(int)wait: (pid_t)pid {
std::atomic_exchange(&_pid, -1);
int status = 0;
for(;;) {
int ok = waitpid(pid, &status, WNOHANG);
if (ok >= 0) break;
if (errno == EINTR) continue;
NSLog(@"waitpid(%d): %s", pid, strerror(errno));
break;
}
return status;
} }
-(void)monitor { -(void)monitor {
int fd = _fd; int fd = _fd;
int pid = _pid; pid_t pid = _pid;
int q = kqueue();
struct kevent events[2] = {};
EV_SET(&events[0], pid, EVFILT_PROC, EV_ADD | EV_RECEIPT, NOTE_EXIT | NOTE_EXITSTATUS, 0, NULL);
EV_SET(&events[1], fd, EVFILT_READ, EV_ADD | EV_RECEIPT, 0, 0, NULL);
int flags; int flags;
// non-blocking io. // non-blocking io.
if (fcntl(_fd, F_GETFL, &flags) < 0) flags = 0; if (fcntl(_fd, F_GETFL, &flags) < 0) flags = 0;
fcntl(_fd, F_SETFL, flags | O_NONBLOCK); fcntl(_fd, F_SETFL, flags | O_NONBLOCK);
kevent(q, events, 2, NULL, 0, NULL);
[_emulatorView childBegan]; [_emulatorView childBegan];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); _thread = [[NSThread alloc] initWithBlock: ^(){
struct kevent events[2] = {};
_wait_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, bool stop = false;
pid, DISPATCH_PROC_EXIT, queue); int status = 0;
if (_wait_source)
{ while (!stop) {
dispatch_source_set_event_handler(_wait_source, ^{ int n = kevent(q, NULL, 0, events, 2, NULL);
if (n <= 0) {
int status = 0; NSLog(@"kevent");
int ok;
for(;;) {
ok = waitpid(pid, &status, WNOHANG);
if (ok >= 0) break;
if (errno == EINTR) continue;
break; break;
} }
_pid = 0;
//dispatch_async(dispatch_get_main_queue(), ^(){
[_emulatorView childFinished: status];
//});
dispatch_source_cancel(_wait_source);
dispatch_release(_wait_source);
_wait_source = nullptr;
});
dispatch_resume(_wait_source);
}
#if 0 for (unsigned i = 0; i < n; ++i) {
dispatch_io_t io = dispatch_io_create(DISPATCH_IO_STREAM, fd, queue, ^(int error){ const auto &e = events[i];
close(fd); unsigned flags = e.flags;
NSLog(@"dispatch_io_create: %d", error); if (e.filter == EVFILT_READ) {
}); int fd = (int)e.ident;
if (flags & EV_EOF) {
dispatch_io_read(io, 0, SIZE_MAX, queue, ^(bool done, dispatch_data_t data, int error){ NSLog(@"EV_EOF");
if (error) {
NSLog(@"dispatch_io_read: %d", error);
dispatch_io_close(io, DISPATCH_IO_STOP);
return;
}
dispatch_data_apply(data, ^(dispatch_data_t, size_t, const void *buffer, size_t size){
[_emulatorView processData: (uint8_t *)buffer size: size];
return true;
} );
if (done) {
NSLog(@"closing fd");
dispatch_io_close(io, DISPATCH_IO_STOP);
return;
}
});
#else
_read_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ,
fd, 0, queue);
if (_read_source)
{
// Install the event handler
dispatch_source_set_event_handler(_read_source, ^{
static uint8_t sbuffer[1024];
size_t estimated = dispatch_source_get_data(_read_source);
estimated = std::max(estimated, sizeof(sbuffer));
uint8_t *buffer = estimated > sizeof(sbuffer) ? (uint8_t *)malloc(estimated) : sbuffer;
if (buffer)
{
ssize_t actual;
for (;;) {
actual = read(fd, buffer, estimated);
//fprintf(stderr, "read: %ld\n", actual);
if (actual < 0) {
if (errno == EINTR) continue;
if (errno == EAGAIN) {
if (buffer != sbuffer) free(buffer);
return;
}
NSLog(@"read: %s", strerror(errno));
dispatch_source_cancel(_read_source);
dispatch_release(_read_source);
_read_source = nullptr;
} }
break;
if (flags & EV_ERROR) {
NSLog(@"EV_ERROR");
}
[self read: fd];
continue;
} }
if (actual > 0) [_emulatorView processData: buffer size: actual]; if (e.filter == EVFILT_PROC) {
if (buffer != sbuffer) free(buffer); pid_t pid = (pid_t)e.ident;
NSLog(@"Child finished");
if (actual == 0) { status = [self wait: pid];
dispatch_source_cancel(_read_source); stop = true;
dispatch_release(_read_source);
_read_source = nullptr;
} }
} }
}); }
if (![_thread isCancelled]) {
// read any lingering io...
dispatch_source_set_cancel_handler(_read_source, ^{ [self read: fd];
NSLog(@"closing fd");
_fd = -1; [_emulatorView childFinished: status];
[_emulatorView setFd: -1]; }
close(fd); close(q);
}); close(fd);
dispatch_resume(_read_source); _fd = -1;
} //NSLog(@"Closing fd");
#endif }];
[_thread start];
} }
#pragma mark - #pragma mark -
@@ -380,28 +360,11 @@
-(void)windowWillClose:(NSNotification *)notification -(void)windowWillClose:(NSNotification *)notification
{ {
pid_t pid = std::atomic_exchange(&_pid, -1);
[_thread cancel];
if (_wait_source) { if (pid > 0) {
dispatch_source_cancel(_wait_source); kill(pid, 9);
dispatch_release(_wait_source);
}
if (_read_source) {
dispatch_source_cancel(_read_source);
dispatch_release(_read_source);
}
int status;
int ok;
if (_pid) {
kill(_pid, 9);
for(;;) {
ok = waitpid(_pid, &status, 0);
if (ok >= 0) break;
if (errno == EINTR) continue;
perror("waitpid: ");
break;
}
} }
[self autorelease]; [self autorelease];

View File

@@ -33,6 +33,8 @@
B61EF7D81482FB6D008C1891 /* titlebar-left.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D51482FB6D008C1891 /* titlebar-left.png */; }; B61EF7D81482FB6D008C1891 /* titlebar-left.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D51482FB6D008C1891 /* titlebar-left.png */; };
B61EF7D91482FB6D008C1891 /* titlebar-right.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D61482FB6D008C1891 /* titlebar-right.png */; }; B61EF7D91482FB6D008C1891 /* titlebar-right.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D61482FB6D008C1891 /* titlebar-right.png */; };
B638188214A179D60027D007 /* ColorView.m in Sources */ = {isa = PBXBuildFile; fileRef = B638188114A179D60027D007 /* ColorView.m */; }; B638188214A179D60027D007 /* ColorView.m in Sources */ = {isa = PBXBuildFile; fileRef = B638188114A179D60027D007 /* ColorView.m */; };
B6407804201CE8BD00D3F2D1 /* GNOConsole.mm.ragel in Resources */ = {isa = PBXBuildFile; fileRef = B612F45B12DD5DF1005D1B77 /* GNOConsole.mm.ragel */; };
B6407805201CE93500D3F2D1 /* GNOConsole.mm.ragel in Sources */ = {isa = PBXBuildFile; fileRef = B612F45B12DD5DF1005D1B77 /* GNOConsole.mm.ragel */; };
B66412391480A070003BC8D3 /* EmulatorWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = B66412381480A070003BC8D3 /* EmulatorWindow.m */; }; B66412391480A070003BC8D3 /* EmulatorWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = B66412381480A070003BC8D3 /* EmulatorWindow.m */; };
B675F4A81E540394004B0D9C /* Screen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B612F44D12DD5DAD005D1B77 /* Screen.cpp */; }; B675F4A81E540394004B0D9C /* Screen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B612F44D12DD5DAD005D1B77 /* Screen.cpp */; };
B675F4A91E561D20004B0D9C /* Apple80.mm.ragel in Sources */ = {isa = PBXBuildFile; fileRef = B612F45712DD5DF1005D1B77 /* Apple80.mm.ragel */; }; B675F4A91E561D20004B0D9C /* Apple80.mm.ragel in Sources */ = {isa = PBXBuildFile; fileRef = B612F45712DD5DF1005D1B77 /* Apple80.mm.ragel */; };
@@ -43,7 +45,6 @@
B67B3CE612B6FA040033AE07 /* a2-charset-80.png in Resources */ = {isa = PBXBuildFile; fileRef = B67B3CE412B6FA040033AE07 /* a2-charset-80.png */; }; B67B3CE612B6FA040033AE07 /* a2-charset-80.png in Resources */ = {isa = PBXBuildFile; fileRef = B67B3CE412B6FA040033AE07 /* a2-charset-80.png */; };
B6801BD912EB549300B22E9E /* vt100-charset.png in Resources */ = {isa = PBXBuildFile; fileRef = B6801BD812EB549300B22E9E /* vt100-charset.png */; }; B6801BD912EB549300B22E9E /* vt100-charset.png in Resources */ = {isa = PBXBuildFile; fileRef = B6801BD812EB549300B22E9E /* vt100-charset.png */; };
B68E632A12FF909D00EAFF5F /* ExampleView.m in Sources */ = {isa = PBXBuildFile; fileRef = B68E632912FF909C00EAFF5F /* ExampleView.m */; }; B68E632A12FF909D00EAFF5F /* ExampleView.m in Sources */ = {isa = PBXBuildFile; fileRef = B68E632912FF909C00EAFF5F /* ExampleView.m */; };
B6ACA2AC1E5C8BEC000E774B /* GNOConsole.mm in Sources */ = {isa = PBXBuildFile; fileRef = B6ACA2AB1E5C8BEC000E774B /* GNOConsole.mm */; };
B6ACA2AD1E614E38000E774B /* VT52.mm in Sources */ = {isa = PBXBuildFile; fileRef = B612F46312DD5DF1005D1B77 /* VT52.mm */; }; B6ACA2AD1E614E38000E774B /* VT52.mm in Sources */ = {isa = PBXBuildFile; fileRef = B612F46312DD5DF1005D1B77 /* VT52.mm */; };
B6ACA2AF1E635CEC000E774B /* vt52-charset.png in Resources */ = {isa = PBXBuildFile; fileRef = B6ACA2AE1E635CEC000E774B /* vt52-charset.png */; }; B6ACA2AF1E635CEC000E774B /* vt52-charset.png in Resources */ = {isa = PBXBuildFile; fileRef = B6ACA2AE1E635CEC000E774B /* vt52-charset.png */; };
B6C704EF15CCC64100CC0401 /* titlebar-center@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6C704EC15CCC64100CC0401 /* titlebar-center@2x.png */; }; B6C704EF15CCC64100CC0401 /* titlebar-center@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6C704EC15CCC64100CC0401 /* titlebar-center@2x.png */; };
@@ -424,6 +425,7 @@
B676065111DEBAE900D6B66C /* TermWindow.xib in Resources */, B676065111DEBAE900D6B66C /* TermWindow.xib in Resources */,
B67B3CE512B6FA040033AE07 /* a2-charset-40.png in Resources */, B67B3CE512B6FA040033AE07 /* a2-charset-40.png in Resources */,
B67B3CE612B6FA040033AE07 /* a2-charset-80.png in Resources */, B67B3CE612B6FA040033AE07 /* a2-charset-80.png in Resources */,
B6407804201CE8BD00D3F2D1 /* GNOConsole.mm.ragel in Resources */,
B6801BD912EB549300B22E9E /* vt100-charset.png in Resources */, B6801BD912EB549300B22E9E /* vt100-charset.png in Resources */,
B61EF7C51481561E008C1891 /* titlebar-corner.png in Resources */, B61EF7C51481561E008C1891 /* titlebar-corner.png in Resources */,
B61EF7C61481561E008C1891 /* titlebar-middle.png in Resources */, B61EF7C61481561E008C1891 /* titlebar-middle.png in Resources */,
@@ -449,6 +451,7 @@
B675F4A91E561D20004B0D9C /* Apple80.mm.ragel in Sources */, B675F4A91E561D20004B0D9C /* Apple80.mm.ragel in Sources */,
B675F4AC1E56A7F2004B0D9C /* GSOSConsole.mm.ragel in Sources */, B675F4AC1E56A7F2004B0D9C /* GSOSConsole.mm.ragel in Sources */,
B6D1CD071E577E7D00C4A6BC /* PTSE.mm.ragel in Sources */, B6D1CD071E577E7D00C4A6BC /* PTSE.mm.ragel in Sources */,
B6407805201CE93500D3F2D1 /* GNOConsole.mm.ragel in Sources */,
8D11072D0486CEB800E47090 /* main.m in Sources */, 8D11072D0486CEB800E47090 /* main.m in Sources */,
256AC3DA0F4B6AC300CF3369 /* TwoTermAppDelegate.mm in Sources */, 256AC3DA0F4B6AC300CF3369 /* TwoTermAppDelegate.mm in Sources */,
B676063B11DEAD3500D6B66C /* TermWindowController.mm in Sources */, B676063B11DEAD3500D6B66C /* TermWindowController.mm in Sources */,
@@ -457,7 +460,6 @@
B61D0D60125B7ACA001C713B /* NewTerminalWindowController.mm in Sources */, B61D0D60125B7ACA001C713B /* NewTerminalWindowController.mm in Sources */,
B61D0D69125B8E06001C713B /* Defaults.m in Sources */, B61D0D69125B8E06001C713B /* Defaults.m in Sources */,
B6ECFF271D2EEA2B00871A81 /* TextLabel.m in Sources */, B6ECFF271D2EEA2B00871A81 /* TextLabel.m in Sources */,
B6ACA2AC1E5C8BEC000E774B /* GNOConsole.mm in Sources */,
B612F45012DD5DAD005D1B77 /* iGeometry.cpp in Sources */, B612F45012DD5DAD005D1B77 /* iGeometry.cpp in Sources */,
B612F45112DD5DAD005D1B77 /* Lock.cpp in Sources */, B612F45112DD5DAD005D1B77 /* Lock.cpp in Sources */,
B612F45212DD5DAD005D1B77 /* OutputChannel.cpp in Sources */, B612F45212DD5DAD005D1B77 /* OutputChannel.cpp in Sources */,

View File

@@ -31,6 +31,13 @@
NSDictionary *parameters; NSDictionary *parameters;
CIFilter *filter; CIFilter *filter;
#if 0
struct sigaction sa = {};
sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_RESTART;
sigaction(SIGCHLD, &sa, NULL);
#endif
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver: self selector: @selector(newTerminal:) name: kNotificationNewTerminal object: nil]; [nc addObserver: self selector: @selector(newTerminal:) name: kNotificationNewTerminal object: nil];

View File

@@ -321,7 +321,7 @@ void Screen::scrollRight(iRect rect, int n) {
auto xIter = line.begin() + rect.minX(); auto xIter = line.begin() + rect.minX();
auto xEnd = line.begin() + rect.maxX(); auto xEnd = line.begin() + rect.maxX();
auto iter = std::copy(xIter, xEnd-n, xEnd); auto iter = std::copy_backward(xIter, xEnd-n, xEnd);
while (n--) { --iter; *iter = char_info(); } while (n--) { --iter; *iter = char_info(); }
} }

BIN
screenshots/cal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

BIN
screenshots/vim.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB