From 9a30c84d0fb6a8c0b4666fc6698ddad4da052a46 Mon Sep 17 00:00:00 2001 From: Cecil Date: Thu, 23 Jul 2015 22:27:13 -0600 Subject: [PATCH] more #127 stuff. update samples/expert-console.rb --- samples/expert-console.rb | 26 ++++++++++---------------- shoes/console/cocoa-term.m | 22 +++++++++++++--------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/samples/expert-console.rb b/samples/expert-console.rb index d5160ddd..37f95b3a 100644 --- a/samples/expert-console.rb +++ b/samples/expert-console.rb @@ -1,4 +1,4 @@ - def getln_raw () + def getln_raw () ln = "" begin loop do @@ -12,7 +12,7 @@ def getln_raw () elsif ch == ?\r $stdout.write("\r\n") return ln - else + else $stdout.putc ch ln += ch end @@ -27,19 +27,19 @@ def getln_raw () para "This will show the console and run a loop that echos keyboard \ input until you enter 'quit' at the beginning of a line. quit will exit Shoes \n" para "Select your input method" - flow { @r1 = radio :io; para "io/console raw"} - flow { @r2 = radio :io; para "io/console cooked"} - flow { @r3 = radio :io; para "readline"} + flow { @r1 = radio :io; para "io/console raw (Not for OSX !)"} + flow { @r2 = radio :io; para "io/console cooked (Not for OSX !)"} + flow { @r3 = radio :io; para "readline (all platforms)" } button "run loop" do Shoes::show_console - if @r1.checked? + if @r1.checked? && RUBY_PLATFORM =~ /linux/ require 'io/console' STDIN.raw! Thread.new do $stdout.write "> " loop do ln = getln_raw - if ln.strip == 'quit' + if ln.strip == 'quit' $stderr.write "really quit (y/n)" ans = getln_raw.strip exit if ans == 'y' @@ -47,14 +47,14 @@ def getln_raw () $stdout.puts "IR: #{ln}" end end - elsif @r2.checked? + elsif @r2.checked? && RUBY_PLATFORM =~ /linux/ require 'io/console' STDIN.cooked! Thread.new do $stdout.write "> " loop do ln = STDIN.cooked(&:gets) - if ln.strip == 'quit' + if ln.strip == 'quit' $stderr.write "really quit (y/n)" ans = $stdin.gets.strip exit if ans == 'y' @@ -67,7 +67,7 @@ def getln_raw () Thread.new do loop do ln = Readline.readline('> ', false) - if ln.strip == 'quit' + if ln.strip == 'quit' $stderr.write "really quit (y/n)" ans = Readline.readline.strip exit if ans == 'y' @@ -79,9 +79,3 @@ def getln_raw () end end end - - #ln = $stdin.gets - #ln = $stdin.readline - - #ln = STDIN.cooked(&:gets) - diff --git a/shoes/console/cocoa-term.m b/shoes/console/cocoa-term.m index 1f6a5507..a75ce58e 100644 --- a/shoes/console/cocoa-term.m +++ b/shoes/console/cocoa-term.m @@ -84,7 +84,7 @@ - (void)consoleInitWithFont: (NSFont *) font [self setDelegate: (id )self]; // setup the copy and clear buttons (yes command key handling would be better) //btnpnl = [[NSBox alloc] initWithFrame: NSMakeRect(0,height-PNLH,width,PNLH)]; - btnpnl = [[NSBox alloc] initWithFrame: NSMakeRect(0,height-btnPanelH,width,btnPanelH)]; + btnpnl = [[NSBox alloc] initWithFrame: NSMakeRect(0,height,width,btnPanelH)]; [btnpnl setTitlePosition: NSNoTitle ]; [btnpnl setAutoresizingMask: NSViewWidthSizable|NSViewMinYMargin]; // draw the icon @@ -95,14 +95,14 @@ - (void)consoleInitWithFont: (NSFont *) font [ictl setImage: icon]; [ictl setEditable: false]; - clrbtn = [[NSButton alloc] initWithFrame: NSMakeRect(400, 2, 60, 28)]; + clrbtn = [[NSButton alloc] initWithFrame: NSMakeRect(300, 2, 60, 28)]; [clrbtn setButtonType: NSMomentaryPushInButton]; [clrbtn setBezelStyle: NSRoundedBezelStyle]; [clrbtn setTitle: @"Clear"]; [clrbtn setTarget: self]; [clrbtn setAction: @selector(handleClear:)]; - cpybtn = [[NSButton alloc] initWithFrame: NSMakeRect(500, 2, 60, 28)]; + cpybtn = [[NSButton alloc] initWithFrame: NSMakeRect(400, 2, 60, 28)]; [cpybtn setButtonType: NSMomentaryPushInButton]; [cpybtn setBezelStyle: NSRoundedBezelStyle]; [cpybtn setTitle: @"Copy"]; @@ -128,17 +128,21 @@ - (void)consoleInitWithFont: (NSFont *) font [termLayout addTextContainer:termContainer]; //termView = [[ConsoleTermView alloc] initWithFrame: textViewBounds]; - termView = [[ConsoleTermView alloc] initWithFrame: NSMakeRect(0, height, width, height-btnPanelH)]; - termpnl = [[NSScrollView alloc] initWithFrame: textViewBounds]; + //termView = [[ConsoleTermView alloc] initWithFrame: NSMakeRect(0, height, width, height-btnPanelH)]; + termView = [[ConsoleTermView alloc] initWithFrame: NSMakeRect(0, 0, width, height)]; + + termpnl = [[NSScrollView alloc] initWithFrame: NSMakeRect(0, 0, width, height)]; [termpnl setHasVerticalScroller: YES]; + //causes btnpnl to vanish. Fixes many resizing issues though: + [termpnl setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [termpnl setDocumentView: termView]; // Put the panels in the Window - cntview = [[NSView alloc] initWithFrame: NSMakeRect(0,height,width,height)]; + cntview = [[NSView alloc] initWithFrame: NSMakeRect(0,height+btnPanelH,width,height+btnPanelH)]; + [self setContentView: cntview]; [cntview setAutoresizesSubviews: YES]; [cntview addSubview: btnpnl]; [cntview addSubview: termpnl]; - [self setContentView: cntview]; // Now init the Tesi object - NOTE tesi callbacks are C, which calls Objective-C tobj = newTesiObject("/bin/bash", 80, 24); // first arg not used, 2 and 3 not either @@ -151,13 +155,13 @@ - (void)consoleInitWithFont: (NSFont *) font [termView initView: self withFont: monoFont]; // tell ConsoleTermView what font to use // need to get the handleInput started - // OSX timer resolution less than 0.1 second unlikely + // OSX timer resolution less than 0.1 second unlikely? cnvbfr = [[NSMutableString alloc] initWithCapacity: 4]; pollTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target: self selector:@selector(readStdout:) userInfo: self repeats:YES]; // debug - printf("w = %d, h = %d winh = %d \n", width, height, winRect.size.height); + // printf("w = %d, h = %d winh = %d \n", width, height, winRect.size.height); } -(IBAction)handleClear: (id)sender