{"id":73,"date":"2012-06-27T16:36:00","date_gmt":"2012-06-27T16:36:00","guid":{"rendered":"http:\/\/sdi.thoughtstorms.info\/?p=73"},"modified":"2012-06-27T16:36:00","modified_gmt":"2012-06-27T16:36:00","slug":"command-n-cursor","status":"publish","type":"post","link":"https:\/\/sdi.thoughtstorms.info\/?p=73","title":{"rendered":"Command &#039;n&#039; Cursor"},"content":{"rendered":"<div dir=\"ltr\" trbidi=\"on\">I&#8217;ve been travelling with my trusty (but ageing) eeepc netbook this last week. There&#8217;s much to love about it but it&#8217;s starting to feel slow in comparison with my other machine.<\/p>\n<p>Increasingly when I use the netbook I try to get away with doing things in a ctrl-alt-f1 shell without logging in to the GUI at all. I&#8217;m starting to wish more software could be used in this environment so I began to look at Curses, the standard library for text-window UIs. There&#8217;s a convenient Python wrapper of course. And there&#8217;s another nice library in Python : Cmd, for creating a command-line driven apps. That is, not programs that literally run as small tools on the shell with command-line arguments, but programs which have their own internal &#8220;repl&#8221; style loop which you drive by typing in commands. Cmd handily hides the details from you, letting you declare a subclass of the Cmd class which simply defines handlers for specific commands. It&#8217;s not a million miles away from something I ended up writing to handle the commands in SdiDesk.<\/p>\n<p>For some of my projects it would be useful to combine the two modes : to have Cmd style input driving a 2D textual output using Curses. Unfortunately Cmd and Curses don&#8217;t obviously play well together. \u00a0Both of them want to take over the input, with Curses thinking in terms of keystrokes while Cmd still expects full lines.<\/p>\n<p>Nevertheless, after a bit of exploration, and learning about Curses&#8217;s textpads and Cmd&#8217;s supplementary methods, I&#8217;m starting to get the two to co-operate. As this gist shows :<\/p>\n<p><script src=\"https:\/\/gist.github.com\/3005137.js?file=cmdncurse.py\">\n<\/script><\/p>\n<p>It doesn&#8217;t do anything yet. Just handles a &#8220;greet NAME&#8221; command that prints &#8220;hello NAME&#8221;. And a &#8220;quit&#8221; command that exits the program. But it has combined Cmd inputs with Curses output.<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been travelling with my trusty (but ageing) eeepc netbook this last week. There&#8217;s much to love about it but it&#8217;s starting to feel slow in comparison with my other machine. Increasingly when I use the netbook I try to get away with doing things in a ctrl-alt-f1 shell without logging in to the GUI [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[71,79,91,365,451],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cmd","tag-command-line","tag-curses","tag-python","tag-text"],"_links":{"self":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=73"}],"version-history":[{"count":0,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/73\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}