ncurses in your            hobostoveEric OestrichSLS Conf2012-12-17
Eric Oestrich           SmartLogic Solutionshttp://www.smartlogicsolutions.comtwitter.com/ericoestrichgithub.com/oestrich
DISCLAIMER
I dont know ncurses      very well
This could be the worst   way to do things
Lets begin
gem install ncurses-ruby
Basic SetupNcurses.initscrNcurses.cbreakNcurses.noecho# window initializationNcurses.doupdateNcurses.refresh
Basic TeardownNcurses.echoNcurses.endwin
Let me repeat that     Slide Content
Basic TeardownNcurses.echoNcurses.endwin
If you dont exit cleanly   Your command prompt wont be             happy
Learn to love reset   bin/hobostove || reset
Basic Panels
Panels - Setup@win = Ncurses.newwin(  height, width,  starty, startx #its backwards)Ncurses.box(@win, 0, 0)@panel =  Ncurs...
Panels - Refresh# setup panelsNcurses::Panel.update_panelsNcurses.doupdateNcurses.refresh
Panels - OutputNcurses.werase(@win)@win.mvaddstr(y, x, "Hello")Ncurses.box(@win, 0, 0)# refresh
Re-implementing readline   or I didnt look to see if I could use               it in hobostove
User Inputwhile (ch = Ncurses.getch)  case ch  when 10 # enter    message = ""  else    message = message + ch.chr.to_s  e...
User Input - Move cursor@win.mvaddstr(1, 2, message)Ncurses.move(  Ncurses.LINES - 2,  message.size + 2)
Abstract into Panels● Handle most of this by itself● Subclass for different panel  types   ○ InputPanel   ○ UserPanel
Scrolling
SorryCouldnt get that to work
Trip ups
Modifier Keyswhile (ch = Ncurses.getch)  case ch  when 14 # C+n  when 10 # enter and C+j  endend
Bonus: GLIDSL for creating command line             apps
GLIrequire gliinclude GLI::Appprogram_desc "A command lineCampfire client"# commands
GLI# set updesc "Start hobostove"command :start do |c|  c.action do    # stuff  endenddefault_command :startexit run(ARGV)
What it gives you
Questions?http://www.smartlogicsolutions.comhttp://www.twitter.com/smartlogichttp://www.github.com/smartlogichttp://www.fa...
Upcoming SlideShare
Loading in …5
×

ncurses in your hobostove

1,244 views
1,088 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,244
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

ncurses in your hobostove

  1. 1. ncurses in your hobostoveEric OestrichSLS Conf2012-12-17
  2. 2. Eric Oestrich SmartLogic Solutionshttp://www.smartlogicsolutions.comtwitter.com/ericoestrichgithub.com/oestrich
  3. 3. DISCLAIMER
  4. 4. I dont know ncurses very well
  5. 5. This could be the worst way to do things
  6. 6. Lets begin
  7. 7. gem install ncurses-ruby
  8. 8. Basic SetupNcurses.initscrNcurses.cbreakNcurses.noecho# window initializationNcurses.doupdateNcurses.refresh
  9. 9. Basic TeardownNcurses.echoNcurses.endwin
  10. 10. Let me repeat that Slide Content
  11. 11. Basic TeardownNcurses.echoNcurses.endwin
  12. 12. If you dont exit cleanly Your command prompt wont be happy
  13. 13. Learn to love reset bin/hobostove || reset
  14. 14. Basic Panels
  15. 15. Panels - Setup@win = Ncurses.newwin( height, width, starty, startx #its backwards)Ncurses.box(@win, 0, 0)@panel = Ncurses::Panel.new_panel(@win)# refresh
  16. 16. Panels - Refresh# setup panelsNcurses::Panel.update_panelsNcurses.doupdateNcurses.refresh
  17. 17. Panels - OutputNcurses.werase(@win)@win.mvaddstr(y, x, "Hello")Ncurses.box(@win, 0, 0)# refresh
  18. 18. Re-implementing readline or I didnt look to see if I could use it in hobostove
  19. 19. User Inputwhile (ch = Ncurses.getch) case ch when 10 # enter message = "" else message = message + ch.chr.to_s end # move cursor and display messageend
  20. 20. User Input - Move cursor@win.mvaddstr(1, 2, message)Ncurses.move( Ncurses.LINES - 2, message.size + 2)
  21. 21. Abstract into Panels● Handle most of this by itself● Subclass for different panel types ○ InputPanel ○ UserPanel
  22. 22. Scrolling
  23. 23. SorryCouldnt get that to work
  24. 24. Trip ups
  25. 25. Modifier Keyswhile (ch = Ncurses.getch) case ch when 14 # C+n when 10 # enter and C+j endend
  26. 26. Bonus: GLIDSL for creating command line apps
  27. 27. GLIrequire gliinclude GLI::Appprogram_desc "A command lineCampfire client"# commands
  28. 28. GLI# set updesc "Start hobostove"command :start do |c| c.action do # stuff endenddefault_command :startexit run(ARGV)
  29. 29. What it gives you
  30. 30. Questions?http://www.smartlogicsolutions.comhttp://www.twitter.com/smartlogichttp://www.github.com/smartlogichttp://www.facebook.com/smartlogic

×