From: Jonathan Hartley on 28 Jul 2010 05:49 On Jul 28, 8:08 am, Ulrich Eckhardt <eckha...(a)satorlaser.com> wrote: > Daniel Fetchinson wrote: > > After getting the technicalities out of the way, maybe I should have > > asked: > > > Is it only me or others would find a platform independent python API > > to clear the terminal useful? > > There are two kinds of programs: > 1. Those that process input to output. If one of those suddenly started by > clearing my screen, I'd just dump it. Also, if output is redirected to a > file or piped into another program, that is basically useless or even > hurting, since you then end up with control sequences in the file. > > 2. Those that provide a text-based interactive UI. Those typically not only > clear the screen, but also control its whole layout and content, so there > you don't only need ways to clear the screen but also to position the > cursor or draw boxes etc. In that case you need a full "curses" library. > > Summary: No, I don't see the need for such an API. > > Cheers! > > Uli > > -- > Sator Laser GmbH > Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 I don't know much, but just in case the following is useful to anyone: There is a Windows program called 'ansicon', which when installed (run with '-i'), will modify all future Windows cmd shells to correctly intercept and interpret ANSI escape codes for colors, cursor movement, and: \e[#J ED: Erase Display which I presume is what is under discussion here. I understand there are other historical ANSI drivers which were responsible for achieving a similar thing under Windows, but this is the method I currently use (on XP) and am very happy with. Also, and probably less usefully, personally I do wish Python provided a cross platform mechanism for simple terminal control like clearing and colored text. Since ANSI codes are used everywhere except Windows, it would make sense to base such a system on them. So I started a pure Python implementation of a crude ANSI driver, on PyPI as 'colorama'. It does nothing on non-windows systems, but on Windows it patches sys.stdout with a stream-like object, in order to filter out ANSI codes and convert them into Win32 terminal control calls. It currently only works with colors and brightness, but I would love to extend it to cover other ANSI codes such as 'clear screen'. It is doubtless riddled with errors and misunderstandings, and I would love any feedback helping me do a better job. Best regards, Jonathan
From: Daniel Fetchinson on 28 Jul 2010 07:23 >> After getting the technicalities out of the way, maybe I should have >> asked: >> >> Is it only me or others would find a platform independent python API >> to clear the terminal useful? > > There are two kinds of programs: > 1. Those that process input to output. If one of those suddenly started by > clearing my screen, I'd just dump it. Also, if output is redirected to a > file or piped into another program, that is basically useless or even > hurting, since you then end up with control sequences in the file. > > 2. Those that provide a text-based interactive UI. Those typically not only > clear the screen, but also control its whole layout and content, so there > you don't only need ways to clear the screen but also to position the > cursor or draw boxes etc. In that case you need a full "curses" library. > > Summary: No, I don't see the need for such an API. Okay, that makes perfect sense, thanks for the exaplanation! I'll just live with the platform.system( ) check for this particular problem then. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown
From: Daniel Fetchinson on 28 Jul 2010 07:25 >> > After getting the technicalities out of the way, maybe I should have >> > asked: >> >> > Is it only me or others would find a platform independent python API >> > to clear the terminal useful? > I don't know much, but just in case the following is useful to anyone: > > There is a Windows program called 'ansicon', which when installed (run > with '-i'), will modify all future Windows cmd shells to correctly > intercept and interpret ANSI escape codes for colors, cursor movement, > and: > > \e[#J ED: Erase Display > > which I presume is what is under discussion here. I understand there > are other historical ANSI drivers which were responsible for achieving > a similar thing under Windows, but this is the method I currently use > (on XP) and am very happy with. > > Also, and probably less usefully, personally I do wish Python provided > a cross platform mechanism for simple terminal control like clearing > and colored text. Since ANSI codes are used everywhere except Windows, > it would make sense to base such a system on them. So I started a pure > Python implementation of a crude ANSI driver, on PyPI as 'colorama'. > It does nothing on non-windows systems, but on Windows it patches > sys.stdout with a stream-like object, in order to filter out ANSI > codes and convert them into Win32 terminal control calls. It currently > only works with colors and brightness, but I would love to extend it > to cover other ANSI codes such as 'clear screen'. It is doubtless > riddled with errors and misunderstandings, and I would love any > feedback helping me do a better job. Thanks, I didn't know about 'colorama' before but it surely looks promising! I'll look into it for future reference, once in a while I like having pretty output without the hassle of 'curses' or other complicated stuff. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown
From: Emile van Sebille on 28 Jul 2010 11:22 On 7/28/2010 4:23 AM Daniel Fetchinson said... > > Okay, that makes perfect sense, thanks for the exaplanation! > I'll just live with the platform.system( ) check for this particular > problem then. > If all else fails, repeating 24 (or 40,60?) lines feeds clears the screen cross platform. Emile
From: Jonathan Hartley on 28 Jul 2010 11:45
On Jul 28, 8:08 am, Ulrich Eckhardt <eckha...(a)satorlaser.com> wrote: > Daniel Fetchinson wrote: > > After getting the technicalities out of the way, maybe I should have > > asked: > > > Is it only me or others would find a platform independent python API > > to clear the terminal useful? > > There are two kinds of programs: > 1. Those that process input to output. If one of those suddenly started by > clearing my screen, I'd just dump it. Also, if output is redirected to a > file or piped into another program, that is basically useless or even > hurting, since you then end up with control sequences in the file. > > 2. Those that provide a text-based interactive UI. Those typically not only > clear the screen, but also control its whole layout and content, so there > you don't only need ways to clear the screen but also to position the > cursor or draw boxes etc. In that case you need a full "curses" library. > > Summary: No, I don't see the need for such an API. > > Cheers! > > Uli > > -- > Sator Laser GmbH > Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 Hey, Your point seems good and I don't mean to contradict, but out of interest, what do you think about an example like the following: I want to write a quick script which, notices whenever I save my source code, and re-runs the unit tests, displaying the output. I think I'd like it to clear the terminal before each re-run of the tests, so that it's immediately obvious what is output from the current run, as opposed to previous runs. Then I can keep my editor focussed, but leave that running in a terminal and trust it to simply display the current output from my tests. I did dash off a quick and dirty version of this once which did a system 'clear' or 'cls' depending on the platform, but to my dismay I found that on Windows this caused focus to jump briefly to the terminal every time it ran 'clear' (!), making it extremely annoying in use. So I wished there had been a simple cross-platform way to clear the terminal. (this, and printing colored text, was my initial use case for starting 'colorama') Is this a silly desire of mine, or simply an uncommon edge case that therefore isn't really significant? Best regards, Jonathan |