Skip to content

Commit

Permalink
more #127 stuff. update samples/expert-console.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecil committed Jul 24, 2015
1 parent de06b3d commit 9a30c84
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
26 changes: 10 additions & 16 deletions samples/expert-console.rb
@@ -1,4 +1,4 @@
def getln_raw ()
def getln_raw ()
ln = ""
begin
loop do
Expand All @@ -12,7 +12,7 @@ def getln_raw ()
elsif ch == ?\r
$stdout.write("\r\n")
return ln
else
else
$stdout.putc ch
ln += ch
end
Expand All @@ -27,34 +27,34 @@ 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'
end
$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'
Expand All @@ -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'
Expand All @@ -79,9 +79,3 @@ def getln_raw ()
end
end
end

#ln = $stdin.gets
#ln = $stdin.readline

#ln = STDIN.cooked(&:gets)

22 changes: 13 additions & 9 deletions shoes/console/cocoa-term.m
Expand Up @@ -84,7 +84,7 @@ - (void)consoleInitWithFont: (NSFont *) font
[self setDelegate: (id <NSWindowDelegate>)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
Expand All @@ -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"];
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9a30c84

Please sign in to comment.