[Boa Constr] Boa's new handling of stdin in ShellEditor
Status: Beta
Brought to you by:
riaan
From: Patrick K. O'B. <po...@or...> - 2001-07-13 13:56:39
|
Riaan, This is probably pretty nitpicky, but I'm not crazy about the new way that stdin works in the Shell for three reasons. First, the behavior isn't the same as other IDEs, such as IDLE. Second, the additional prompt is a distraction when most programs that use stdin already display a prompt. Third, it is too easy to move the cursor back to a previous command and copy that line down which displays the ps1 prompt instead of ps4, etc. For examples of what I mean you can type help() or license(). Now, I tried to change this in Boa so that it was still "inline" as opposed to a wxTextEntryDialog but then I ran into problems with the hardcoded expectation of a 4 character prompt so I gave up. One alternative is to go back to a wxTextEntryDialog and redefine both stdin and raw_input (at the __builtin__ level, not locals, which was the problem with the previous code I believe). For example: def readRaw(self, prompt='Please enter your response:'): dialog = wxTextEntryDialog(None, prompt, \ 'Input Dialog (Raw)', '') try: if dialog.ShowModal() == wxID_OK: text = dialog.GetValue() return text finally: dialog.Destroy() return '' And then wherever appropriate add: import __builtin__ __builtin__.raw_input = readRaw # Or the equivalent if readRaw is passed as a parameter. del __builtin__ To do this, though, would require more changes to Boa than I was comfortable making. And I wasn't sure you would agree with these changes. It's not like anything is really broken, I'm just looking for a better solution and wanted to jot this stuff down while it was fresh in my mind. Feel free to disregard this message entirely. I just felt compelled to write it. To me the best solution would be something inline that wasn't so fragile. It shouldn't display a prompt but it must be aware of the prompt that might be passed to raw_input(), or that was written directly to stdout (which is all that raw_input does anyway). In a way I think it should be modal, which is what you get with the dialog approach. There is also the issue of whether to leave the prompt and response in the output stream, which looks pretty ugly in the case of license(). My readRaw() method basically swallows the prompt and response, which looks better when you call license() but might be inappropriate in other circumstances where you want the prompt and response logged. As you can see, I'm still looking for a solution. --- Patrick K. O'Brien Orbtech "I am, therefore I think." |