Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Use curses, don't swear by Sean Zicari

Afcfefa1f067d10bd021de0cc2e5e806?s=47 PyCon 2013
March 18, 2013

Use curses, don't swear by Sean Zicari

Afcfefa1f067d10bd021de0cc2e5e806?s=128

PyCon 2013

March 18, 2013
Tweet

More Decks by PyCon 2013

Other Decks in Technology

Transcript

  1. None
  2. Use curses... don't swear an overview of terminal control in

    python
  3. . Web Developer . Love all things low level .

    Love computer history whoami
  4. . Web Developer . Love all things low level .

    Love computer history whoami
  5. . Web Developer . Love all things low level .

    Love computer history whoami
  6. . Cars.com . PyCon sponsor . Python/Postgres shop . Awesome

    place to work! where do I work
  7. . Cars.com . PyCon sponsor . Python/Postgres shop . Awesome

    place to work! where do I work
  8. . Cars.com . PyCon sponsor . Python/Postgres shop . Awesome

    place to work! where do I work
  9. . Cars.com . PyCon sponsor . Python/Postgres shop . Awesome

    place to work! where do I work
  10. video terminals!

  11. . First VT ~1969 . Basic line/screen control . ASCII

    character set . ~300 baud (characters/second) video terminals!
  12. . First VT ~1970 . Basic line control . ASCII

    character set . ~300 baud (characters/second) video terminals! VT-100
  13. . Kernel handled data transfer . Terminal handled display (cursor,

    color, line handling...) . Terminal control through escape sequences talking to a terminal
  14. . Vendor-specific escape sequences . ECMA-48 adopted in 1976 .

    termcap released in 1978 (TERMinal CAPability) standards? nope. Esc[20h Set new line mode LMN Esc[?1h Set cursor key to application DECCKM none Set ANSI (versus VT52) DECANM Esc[?3h Set number of columns to 132 DECCOLM Esc[?4h Set smooth scrolling DECSCLM Esc[?5h Set reverse video on screen DECSCNM Esc[?6h Set origin to relative DECOM Esc[?7h Set auto-wrap mode DECAWM Esc[?8h Set auto-repeat mode DECARM Esc[?9h Set interlacing mode DECINLM
  15. . Vendor-specific escape sequences . ECMA-48 adopted in 1976 .

    termcap released in 1978 (TERMinal CAPability) standards? nope.
  16. . Vendor-specific escape sequences . ECMA-48 adopted in 1976 .

    termcap released in 1978 (TERMinal CAPability) standards? nope.
  17. line discipline

  18. line discipline . Glue code . No execution context .

    line modes: "raw" or "cooked"
  19. introducing (n)curses . Developed for BSD . Code borrowed from

    vi . Originally used termcap . Unix System III / V . Gained additional features . Curses became pcurses . pcurses became n(ew)curses
  20. why (n)curses? . Plethora of terminals . Plethora of escape

    sequence variations . Portable . Convenient abstractions . Standardized API
  21. (n)curses philosophy . Tools provided... . ...but you're on your

    own . One primary object: stdscr . Full cursor/screen control . Forms, windows, colors, cbreak mode . Manual Screen refresh
  22. program dissection

  23. program dissection

  24. program dissection

  25. program dissection

  26. program dissection

  27. program dissection

  28. program dissection

  29. program dissection

  30. . Pronounced "oor'-wid" . Layered architecture . Display modules .

    Widget layout . Event loops introducing urwid
  31. . Pronounced "oor'-wid" . Layered architecture . Display modules .

    Widget layout . Event loops introducing urwid
  32. . Pronounced "oor'-wid" . Layered architecture . Display modules .

    Widget layout . Event loops introducing urwid
  33. . Pronounced "oor'-wid" . Layered architecture . Display modules .

    Widget layout . Event loops introducing urwid
  34. . Pronounced "oor'-wid" . Layered architecture . Display modules .

    Widget layout . Event loops introducing urwid
  35. program dissection

  36. resources Python Curses ------------- . Documentation http://docs.python.org/2/library/curses.html . Tutorial http://docs.python.org/2/howto/curses.html

    Urwid ----- . Documentation http://excess.org/urwid/docs/ . Tutorials http://excess.org/urwid/docs/tutorial/index.html#urwid-tutorial . Manual http://excess.org/urwid/docs/manual/index.html#urwid-manual