[Python-ideas] Re: New feature to revert 'barry_as_FLUFL' future import

2021-09-18 Thread Jeremiah Vivian
If "barry_as_FLUFL" is a joke, I see no reason why there shouldn't be another 
joke disabling it.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/4IMNS3GQZUEZ5T6ZZFDLZDXYH6BYEOCE/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature to revert 'barry_as_FLUFL' future import

2021-09-17 Thread Stephen J. Turnbull
David Mertz, Ph.D. writes:

 > This feature request comes about 196 days to early.

+195 (from Japan ;-)


___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QK25HIDAQKLOK4HAI5BFP45XOYBTMLFR/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature to revert 'barry_as_FLUFL' future import

2021-09-17 Thread David Mertz, Ph.D.
This feature request comes about 196 days to early.

It is perhaps worth considering on April 1, but not in September.

On Fri, Sep 17, 2021 at 8:59 AM Jeremiah Vivian <
nohackingofkrow...@gmail.com> wrote:

> NEW_FEATURE = "remove_barry_from_BDFL" or
> "barry_resign_as_FLUFL"/"barry_resign_as_BDFL";
>
> Add a new future import NEW_FEATURE. This reverts the effects of the
> future import "barry_as_FLUFL" easter egg IF it is ever imported. This is
> absolutely unnecessary when "barry_as_FLUFL" isn't imported.
>
> There can be optional messages attached to a Barry-related future import:
> - When future import NEW_FEATURE is imported and future import
> "barry_as_FLUFL" is already imported:
> -- "Barry was overthrown from BDFL-ship!" ( friendlier message: "Barry has
> resigned from FLUFL-ship."/"Barry has resigned from BDFL-ship." )
> - When future import "barry_as_FLUFL" is imported and NEW_FEATURE is
> already imported:
> -- "Barry has returned as FLUFL." ( or "Barry has returned as BDFL." )
>
> This idea also suggests allowing future imports anywhere in the file as
> long as it's Barry-related ( optional feature: only allow a Barry-related
> future import IF it is the opposite of the previous Barry-related future
> import. The opposite of "no Barry-related future imports yet" is the future
> import "barry_as_FLUFL" )
>
> Test cases:
> >>> from __future__ import barry_resigned_as_FLUFL # no effect
> >>> from __future__ import barry_as_FLUFL
> >>> 1 <> 2
> True
> >>> 1 != 2
>   File "", line 1
> 1 != 2
>   ^^
> SyntaxError: with Barry as BDFL, use '<>' instead of '!='
> >>> from __future__ import barry_resigned_as_FLUFL
> Barry has resigned from BDFL-ship.
> >>> 1 <> 2
>   File "", line 1
> 1 <> 2
>   ^^
> SyntaxError: invalid syntax
> >>> 1 != 2
> True
> >>> from __future__ import barry_as_FLUFL
> Barry has returned as FLUFL.
> >>> 1 != 2
>   File "", line 1
> 1 != 2
>   ^^
> SyntaxError: with Barry as BDFL, use '<>' instead of '!='
> >>> 1 <> 2
> True
> >>> from __future__ import barry_resigned_as_FLUFL
> Barry has resigned from BDFL-ship.
> >>> 1 != 2
> True
> >>> 1 <> 2
>   File "", line 1
> 1 <> 2
>   ^^
> SyntaxError: invalid syntax
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/2JTDWRAM4OCZPRH3YZQV5IAE3NHURR5O/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JFH2VSCUO3SW3TPH4UDVOYSJCOWPT2QZ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature to revert 'barry_as_FLUFL' future import

2021-09-17 Thread Steven D'Aprano
barry_as_FLUFL is a joke, not a serious feature.

Why do you want to enable it, then remove it? What's your motivation for 
this feature?


-- 
Steve
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JK3GC53BTU562WK7FBC6MKTEERHZGV6X/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-18 Thread Eryk Sun
On 10/18/20, Mike Miller  wrote:
> On 2020-10-17 17:05, Eryk Sun wrote:
>> CMD's CLS is implemented with three API calls:
>> GetConsoleScreenBufferInfo to get the screen-buffer dimensions and
>> default text attributes, ScrollConsoleScreenBufferW to shift the
>> buffer out, and SetConsoleCursorPosition to move the cursor to (0,0).
>
> Would you happen to have a link to some Python/ctypes code to implement
> this?

I would expect this to be implemented in posixmodule.c, not via
ctypes. I can help with the implementation in C. Read the following
pages in the console docs, if you haven't already:

https://docs.microsoft.com/en-us/windows/console/scrolling-the-screen-buffer
https://docs.microsoft.com/en-us/windows/console/scrolling-a-screen-buffer-s-contents
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ZN7UFUZJASVZRXP5NVMM3BXTTYRGDMXW/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-18 Thread Eryk Sun
On 10/18/20, Mike Miller  wrote:
>
> Also, a shell is not a terminal, so terminal routines don't feel right in
> shutil.  Putting get_terminal_size() there was a mistake imho.

The shutil module "offers a number of high-level operations on files".
ISTM that shutil.get_terminal_size is a high-level operation on
sys.__stdout__, if it's a terminal/console device file, though it's an
odd duck since the rest of the module is dealing with filesystem
files. That said, rightly or wrongly, I think of shutil as a
collection of shell utility (SHell UTILity) functions for Python's
standard library, so I'm comfortable with expanding its mandate to
functions commonly supported by CLI shell environments, such as
terminal/console management.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/237RUHNA6IFRXPBBWHH3QHIEUNO77MRG/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-18 Thread Mike Miller



On 2020-10-17 17:05, Eryk Sun wrote:

CMD's CLS is implemented with three API calls:
GetConsoleScreenBufferInfo to get the screen-buffer dimensions and
default text attributes, ScrollConsoleScreenBufferW to shift the
buffer out, and SetConsoleCursorPosition to move the cursor to (0,0).



Would you happen to have a link to some Python/ctypes code to implement this? 
It would be helpful.


-Mike
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/6I6RQNJOXOD6OYHC7XZRJCPUIB55ICAS/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-18 Thread Mike Miller



On 2020-10-17 17:21, Eryk Sun wrote:

On 10/16/20, Rob Cliffe via Python-ideas  wrote:


May I suggest it be called os.clearscreen()?


I'd prefer shutil.clear_screen(). There's already
shutil.get_terminal_size(). I know there's also
os.get_terminal_size(), but its use isn't encouraged.



Clear is fine, it's been a Unix command for decades, while DOS "cls" is too 
terse.  No need to be overly wordy however.  Clear takes a few parameters as 
well, for scrollback etc on a recent Linux.


Also, a shell is not a terminal, so terminal routines don't feel right in 
shutil.  Putting get_terminal_size() there was a mistake imho.


-Mike
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/PLMMF6YC6IFUCRFAJLQXS7CUFF7TP2JH/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-18 Thread Eryk Sun
On 10/17/20, Christopher Barker  wrote:
>
> then how about os.clear_terminal() ?

IMO, an os level function such as os.clear_terminal(fd) should only
support terminal/console devices and would be implemented in
Modules/posixmodule.c. Higher-level behavior and support for IDEs
belongs in shutil.

> Sure, there's a manageable set of default terminals across the major OSs
> (and lInux Desktops), but there are a LOT of others as well, including
> IDEs, and even the new Terminal in Windows:

I would expect os.clear_terminal() to make exceptions only for popular
terminals/consoles, if they don't support the common ANSI sequence to
clear the screen.

In Windows 10, you can enable virtual terminal (VT) mode by default
for all non-legacy console sessions by setting "VirtualTerminalLevel"
to 1 in "HKCU\Console". VT mode supports the standard ANSI sequences
for clearing the terminal and/or scrollback. Regardless of the
VirtualTerminalLevel setting, each tab in Windows Terminal is a
headless pseudoconsole session (ConPTY) that has VT mode enabled by
default.

In all supported versions of Windows, if VT mode is disabled or not
supported, as determined by GetConsoleMode, then the console screen
buffer can be scrolled or cleared via GetConsoleScreenBufferInfo and
ScrollConsoleScreenBuffer, and the cursor can be reset to (0,0) via
SetConsoleCursorPosition.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7TNXGFFPEUUGX7GTL4S4JRV4Q42EJTLL/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-17 Thread Christopher Barker
On Sat, Oct 17, 2020 at 5:23 PM Eryk Sun  wrote:

> I'd prefer shutil.clear_screen(). There's already
> shutil.get_terminal_size(). I know there's also
> os.get_terminal_size(), but its use isn't encouraged.
>

then how about os.clear_terminal() ?

after all, this will not clear the "screen", by pretty much any
modern definition of screen.

I am curious though -- is there any hope of writing even a 90% solution
across all platforms that matter?

This seems to be very much a function of the terminal program, not the
operating system.

Sure, there's a manageable set of default terminals across the major OSs
(and lInux Desktops), but there are a LOT of others as well, including
IDEs, and even the new Terminal in Windows:

https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?rtc=1&activetab=pivot:overviewtab

(which I haven't tried yet -- no handy Windows Box at the moment)

Anyway -- this is an honest question -- I have no idea if there is enough
standardization to make it possible, but maybe someone on this thread does.

-CHB

PS: I use the built in Terminal app on OS-X: cmd+K clears the screen and
scrollback buffer. clearclears the screen, but not the scrollback buffer. I
found this on SO:

https://superuser.com/questions/243693/how-to-reset-teminal-under-mac-os-x-programmatically

which involved calling osascript -- I tried it, and got a dialog asking for
permission for Terminal to access System Events, and then it failed with an
error:

System Events got an error: osascript is not allowed to send keystrokes.

I only spent five minutes on it -- but not straightforward.




-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/4MXECRH73LFDSBMHIAWP64UFSOBPWM3W/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-17 Thread Eryk Sun
On 10/16/20, Rob Cliffe via Python-ideas  wrote:
>
> May I suggest it be called os.clearscreen()?

I'd prefer shutil.clear_screen(). There's already
shutil.get_terminal_size(). I know there's also
os.get_terminal_size(), but its use isn't encouraged.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/RSYOV4KUQOFKUUQETFRXPWJC64RV47RN/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-17 Thread Eryk Sun
On 10/13/20, Mike Miller  wrote:
>
> The legacy Windows console has another limitation in that I don't believe it
> has a single API call to clear the whole thing.  One must iterate over the 
> whole
> buffer and write spaces to each cell, or some similar craziness.

No, it's not really similar craziness -- at least not from the client
program's perspective. The implementation in the console host itself
is probably something like that.

CMD's CLS is implemented with three API calls:
GetConsoleScreenBufferInfo to get the screen-buffer dimensions and
default text attributes, ScrollConsoleScreenBufferW to shift the
buffer out, and SetConsoleCursorPosition to move the cursor to (0,0).

https://docs.microsoft.com/en-us/windows/console/scrollconsolescreenbuffer

The following debugger session is while stepped into CMD's eCls()
function that implements the CLS command. This is just before it calls
ScrollConsoleScreenBufferW, with parameters 1-4 in registers rcx, rdx,
r8, and r9, and parameter 5 on the stack.

lpScrollRectangle (rdx): the entire screen buffer (sized 125 x 9001)
is to be scrolled.

0:000> ?? ((SMALL_RECT *)@rdx)
struct _SMALL_RECT * 0x00e9`be8ff8b8
   +0x000 Left : 0n0
   +0x002 Top  : 0n0
   +0x004 Right: 0n125
   +0x006 Bottom   : 0n9001

dwDestinationOrigin (r9): the target row is -9001, so the contents of
the entire buffer are shifted out.

0:000> ?? (short)(@r9 >> 16)
short 0n-9001

lpFill (rsp / stack): use a space with the default attributes (in my
case background color 0 and foreground color 7, in the current
16-color palette).

0:000> ?? ((CHAR_INFO **)@rsp)[4]->Char.UnicodeChar
wchar_t 0x20 ' '
0:000> ?? ((CHAR_INFO **)@rsp)[4]->Attributes
unsigned short 7
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SYMJ4HM6ZUBA3HMS5QXIDVSMQDRECHFP/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-17 Thread Rob Cliffe via Python-ideas



On 16/10/2020 03:46, Guido van Rossum wrote:


Let's add a function os.clear(), and perhaps IDLE (or some 
enterprising IDLE hacker) can monkey-patch that to do whatever makes 
IDLE's shell reset.


May I suggest it be called os.clearscreen()?  The os module has 
functions related to file systems, processes (maybe others I've missed) 
as well as to the screen so the meaning of os.clear() may not be 
obvious.  (If it clears scroll buffers as well as the physical screen, 
even that name is not completely accurate, but I can't think of anything 
better.)

Best wishes
Rob Cliffe
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/A3DFMP45YDOCCTO5K5JNRE3AYGIVQEJ4/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-17 Thread Holly Short
Not an educator, but since no-one seems to have mentioned this: I often use
"os.system('clear')" for quick and dirty terminal animations, eg. to debug
a maze solver for some competitive coding challenge... Not much of a use
case, and doesn't really matter if it's not portable.

On Tue, 13 Oct 2020 23:36 Guido van Rossum,  wrote:

> Can one of the educators on the list explain why this is such a commonly
> required feature? I literally never feel the need to clear my screen -- but
> I've seen this requested quite a few times in various forms, often as a bug
> report "IDLE does not support CLS". I presume that this is a common thing
> in other programming environments for beginners -- even C++ (given that it
> was mentioned). Maybe it's a thing that command-line users on Windows are
> told to do frequently? What am I missing that students want to do
> frequently? Is it a holdover from the DOS age?
>
> On Tue, Oct 13, 2020 at 11:25 AM Mike Miller 
> wrote:
>
>>
>> On 2020-10-13 06:19, Stestagg wrote:
>> > For example, the pypi `console` library provides a method:
>> `console.sc.reset()`
>> > that behaves similarly to `CLS` on windows and also appears to be
>> fairly
>> > reliable cross-platform.
>>
>>
>> Yes, there is more to it than appears at first glance.  There is
>> resetting the
>> terminal, clearing the currently visible screen, and/or the scrollback
>> buffer as
>> well.
>>
>> The legacy Windows console has another limitation in that I don't believe
>> it has
>> a single API call to clear the whole thing.  One must iterate over the
>> whole
>> buffer and write spaces to each cell, or some similar craziness.  That's
>> why
>> even folks writing C++ just punt and do a system("cls") instead.
>>
>> With the mentioned lib console, the example above prints the ANSI codes
>> to do a
>> terminal reset, and while that works widely these days, it should not be
>> the
>> first choice.  It would be better to use the cross-platform wrapper
>> functions in
>> the console.utils module, either:
>>
>>  # A DOS-like reset, clears screen and scrollback, also aliased to
>> cls()
>>  reset_terminal()
>>
>>  # A Unix-like clear, configurable via param, and aliased to clear()
>>  clear_screen()
>>
>> -Mike
>> ___
>> Python-ideas mailing list -- python-ideas@python.org
>> To unsubscribe send an email to python-ideas-le...@python.org
>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>> Message archived at
>> https://mail.python.org/archives/list/python-ideas@python.org/message/MX54AOXMYJHGRVOO2XW3J7JWHQDDUKPQ/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
>
> --
> --Guido van Rossum (python.org/~guido)
> *Pronouns: he/him **(why is my pronoun here?)*
> 
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/J65P6UELD4RSSCSMAFYF52WADURHX2HL/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BNGLHZNXF5KAEPSAXFYNDLCI554VHMRD/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-17 Thread Marco Sulla
On Sat, 17 Oct 2020 at 21:50, Ethan Furman  wrote:
>
> On 10/17/20 10:54 AM, Marco Sulla wrote:
>
> > I think that in this case `clear` simply writes N enter chars, until
> > the terminal is "cleared". IMHO this is the safest option.
>
> 'clear' should also leave the cursor in the upper-left position, which cannot 
> be gotten by writing a bunch of line feeds.

Because someone wants to support `cls` or `clear` inside a statement?
I suppose it can  be done, but I don't see the use case.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VYT5DK26YJQA55FOQ75NF7A2DSQ6TIVI/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-17 Thread Carl Smith
The IPython terminal has used Python Prompt Toolkit since version 5, so PPT
would be my default choice for any shell or console applications (though I
haven't used it for a few years).

-- Carl Smith
carl.in...@gmail.com


On Sat, 17 Oct 2020 at 20:51, Ethan Furman  wrote:

> On 10/17/20 10:54 AM, Marco Sulla wrote:
>
> > I think that in this case `clear` simply writes N enter chars, until
> > the terminal is "cleared". IMHO this is the safest option.
>
> 'clear' should also leave the cursor in the upper-left position, which
> cannot be gotten by writing a bunch of line feeds.
>
> --
> ~Ethan~
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/IGUKJF6TE33IWOZ4Y7HK6Q2RKP6V6WTD/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/IGNHCNTLFBI3TZN4XKE5RC4VIVTMEHW5/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-17 Thread Ethan Furman

On 10/17/20 10:54 AM, Marco Sulla wrote:


I think that in this case `clear` simply writes N enter chars, until
the terminal is "cleared". IMHO this is the safest option.


'clear' should also leave the cursor in the upper-left position, which cannot 
be gotten by writing a bunch of line feeds.

--
~Ethan~
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/IGUKJF6TE33IWOZ4Y7HK6Q2RKP6V6WTD/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-17 Thread Marco Sulla
On Sat, 17 Oct 2020 at 03:37, Steven D'Aprano  wrote:
>
> On Fri, Oct 16, 2020 at 11:30:56PM +0200, Marco Sulla wrote:
>
> > Well, in terminals like bash, `clear` does not really delete the
> > previous input. It simply move the scroll so the first line of the
> > input is the current input.
>
> That's not actually correct: in bash, `clear` actually deletes the
> scrollback buffer too.
>
> In modern Linuxes, `clear` takes an option `-x` which suppresses that
> behaviour. Perhaps you have an alias?
>
> alias clear='clear -x'

Well, this is interesting. From `man clear`:

clear  clears  your screen if this is possible, including its
scrollback buffer (if the extended “E3” capability is defined).
-x   do not attempt to clear the terminal's scrollback buffer using
the extended “E3” capability.

So probably I always used pseudoterminal without E3 capability.

I think that in this case `clear` simply writes N enter chars, until
the terminal is "cleared". IMHO this is the safest option.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/M6XXYVQAQNTHFT7F33452P6E62CO5GAM/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-17 Thread Eryk Sun
On 10/16/20, Steven D'Aprano  wrote:
>
> On terminals that support it, this should work:
>
> - `print('\33[H\33[2J')`
>
> but I have no idea how to avoid clearing the scrollback buffer on
> Windows, or other posix systems with unusual terminals.

In Windows 10, ANSI sequences and some C1 control characters (e.g.
clear via CSI -- '\x9b2J\x9bH') are supported by a console session if
it's not in legacy mode. The ESC character can be typed as Ctrl+[,
which is useful in the CMD shell, which doesn't support character
escapes such as \33 or \x1b. It can also be set in an %ESC%
environment variable.

Using ANSI sequences and C1 controls requires virtual terminal (VT)
mode to be enabled for the console screen buffer. VT mode is enabled
by default in a pseudoconsole session (e.g. when attached to a tab in
Windows Terminal), but it can be manually disabled. It's also enabled
by default for non-legacy console sessions if "VirtualTerminalLevel"
is set to 1 in "HKCU\Console". Regardless, it's simple to check
whether VT mode is currently enabled for the screen buffer via WinAPI
GetConsoleMode.

If VT mode isn't enabled, the screen buffer can be scrolled using the
console API function ScrollConsoleScreenBuffer using dimensions and
attributes from GetConsoleScreenBufferInfo, and the cursor position
can be set via SetConsoleCursorPosition.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/2JOPCG55LD6I7S6673C3BNTH2EDSLSWH/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Michael Smith
On Fri, Oct 16, 2020 at 22:42 Steven D'Aprano  wrote:

> On Fri, Oct 16, 2020 at 10:28:20PM -0400, David Mertz wrote:
> > On Fri, Oct 16, 2020, 10:16 PM Steven D'Aprano
> >
> > > I think that if we go ahead with this, we shouldn't allow lack
> > > of support for screen and/or tmux to stand in the way. A 99% solution
> is
> > > better than a 0% solution :-)
> > >
> >
> > What manner of savages run a terminal without a multiplexer? :-)
>
> Savages with a terminal that natively supports multiple tabs, and a GUI
> desktop environment that supports multiple terminal windows :-P
>
> I understand using screen or tmux when ssh'ing into a remote machine,
> but what advantage are they when you are using the local machine via a
> GUI?


One advantage is you can outright quit the terminal application and the
session remains active in the multiplexer. Since I'm clumsy, I've been
saved by this more than once.

- Smith
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/F2ZV6OLEVQJ6S6IOX4PGI5N5S6JCXPAP/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread David Mertz
On Fri, Oct 16, 2020, 10:43 PM Steven D'Aprano

> > What manner of savages run a terminal without a multiplexer? :-)
>

I understand using screen or tmux when ssh'ing into a remote machine, but
> what advantage are they when you are using the local machine via a GUI?
>

It was definitely persistent SSH sessions that first got me hooked on
screen, later tmux. I've played around with mosh, but it hasn't entirely
played nice with other aspects of my workflow.

But even purely locally, tmux lets me nohup services (e.g. a flask server
I'm working on) without them dying if terminal closes. Reattaching to the
window the server runs in is simple. And with tmux- resurrect, I can
save/restore the state of the panes I use on restart. A resurrect even
relaunches some applications like htop and vim, and at least puts panes in
the saved PWD if not.

All that said, the folks who want a beginner friendly os.clear() are
probably not ones who tweak tmux plugins and key bindings.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ZMYJLLODD7SQ2TCLHAKXKDU4GA7ULCCZ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Steven D'Aprano
On Fri, Oct 16, 2020 at 10:28:20PM -0400, David Mertz wrote:
> On Fri, Oct 16, 2020, 10:16 PM Steven D'Aprano
> 
> > I think that if we go ahead with this, we shouldn't allow lack
> > of support for screen and/or tmux to stand in the way. A 99% solution is
> > better than a 0% solution :-)
> >
> 
> What manner of savages run a terminal without a multiplexer? :-)

Savages with a terminal that natively supports multiple tabs, and a GUI 
desktop environment that supports multiple terminal windows :-P

I understand using screen or tmux when ssh'ing into a remote machine, 
but what advantage are they when you are using the local machine via a 
GUI?


-- 
Steve
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/NLOTLG3XCUGA6M6VM5OFTY6TOS44VIKG/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread David Mertz
On Fri, Oct 16, 2020, 10:16 PM Steven D'Aprano

> I think that if we go ahead with this, we shouldn't allow lack
> of support for screen and/or tmux to stand in the way. A 99% solution is
> better than a 0% solution :-)
>

What manner of savages run a terminal without a multiplexer? :-)
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VRN2276YBNRWNCGYWXN6UFVPEF6Y4WUR/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Steven D'Aprano
On Fri, Oct 16, 2020 at 09:53:35PM -0400, David Mertz wrote:
> On Fri, Oct 16, 2020 at 9:36 PM Steven D'Aprano  wrote:
> 
> > > Well, in terminals like bash, `clear` does not really delete the
> > > previous input. It simply move the scroll so the first line of the
> > > input is the current input.
> >
> > That's not actually correct: in bash, `clear` actually deletes the
> > scrollback buffer too.
> >
> 
> I never noticed that, since my "terminal" is `tmux` (running inside a Linux
> terminal).  In that case, `clear` might clear the underlying terminal
> scrollback buffer, but it does not clear the tmux scrollback buffer.  The
> `screen` terminal multiplexer is similar.

Oh yeah; I forgot about screen and tmux.

I just tried it in screen, and `os.system('clear')` does not clear the 
scrollback used by screen.

I think that if we go ahead with this, we shouldn't allow lack 
of support for screen and/or tmux to stand in the way. A 99% 
solution is better than a 0% solution :-)


> All of which suggests to me that doing the "same thing" in a platform
> neutral way is not an insignificant effort.

Indeed.



-- 
Steve
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/5NUOVP3HPY5XE4CYVJECYNXOGA3RDIA7/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread David Mertz
On Fri, Oct 16, 2020 at 9:36 PM Steven D'Aprano  wrote:

> > Well, in terminals like bash, `clear` does not really delete the
> > previous input. It simply move the scroll so the first line of the
> > input is the current input.
>
> That's not actually correct: in bash, `clear` actually deletes the
> scrollback buffer too.
>

I never noticed that, since my "terminal" is `tmux` (running inside a Linux
terminal).  In that case, `clear` might clear the underlying terminal
scrollback buffer, but it does not clear the tmux scrollback buffer.  The
`screen` terminal multiplexer is similar.  Both screen and tmux HAVE a way
to clear their scrollback buffer, but it is two different ways between
those popular programs... both different from the `clear` command in the
underlying terminal.

I don't use MacOS anymore, but when I did I used iTerm2, which has a fork
of the tmux code to implement its pane division functionality.  I do not
know whether that very popular terminal clears the actual scrollback with
the `clear` command.  I feel like I remember it not doing that, but it's
been a couple years.

All of which suggests to me that doing the "same thing" in a platform
neutral way is not an insignificant effort.

-- 
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SGWZTDBDTVFQWHCV7RDTUVDY2VY4G4CU/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Steven D'Aprano
On Fri, Oct 16, 2020 at 11:30:56PM +0200, Marco Sulla wrote:

> Well, in terminals like bash, `clear` does not really delete the
> previous input. It simply move the scroll so the first line of the
> input is the current input.

That's not actually correct: in bash, `clear` actually deletes the 
scrollback buffer too.

In modern Linuxes, `clear` takes an option `-x` which suppresses that 
behaviour. Perhaps you have an alias?

alias clear='clear -x'



-- 
Steve
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/3CHBIZOXUPD6OWEKBYISYRDKA3VKO3LO/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Steven D'Aprano
On Sat, Oct 17, 2020 at 05:44:12AM +1100, Chris Angelico wrote:
> On Sat, Oct 17, 2020 at 5:40 AM Jonathan Crall  wrote:
> >
> > I just want to point out that I can think of a valid use case for `clf`. 
> > I'm not sure if it was mentioned.
> >
> > In the case where you have a script that produces a lot of output, a common 
> > task might be scrolling to the beginning to check an output. If your screen 
> > was not fresh, and you had a lot of previous output (say from running the 
> > script multiple times), then it is hard to find the beginning unless you 
> > have previously cleared the screen.
> >
> 
> This is exactly why I think this should NOT be made too easy. That's a
> perfect example of an attractive nuisance: instead of creating a
> divider (say, a half a dozen blank lines, or a row of hyphens with a
> blank or two each side), you're throwing away all information from the
> previous output, making it impossible to compare the two.

Why are we assuming that our "clear screen" command flushes the 
scrollback buffer as well as clearing the screen?

I do not want any cls command to flush the scrollback buffer by default 
(although I wouldn't object to an option to do so). I would want it to 
be more like ^L although that's probably dependent on your terminal.

In other words, I want the default to be like the command `clear -x` 
(bash), not `clear`. I also like the idea given here:

https://askubuntu.com/a/997893

of printing a divider first so that when scrolling back the clear screen 
is obvious.

So here's my first attempt (untested!) of a "cls" pseudo-builtin 
command, similar to the help and quit builtins added by site.py. It 
assumes that os.clear exists and takes an appropriate optional flag.


```
import builtins
import os

class ScreenClearer:
if os.name == 'posix':
def __repr__(self):
return 'Use cls() or Ctrl-L to clear the screen.'
else:
 def __repr__(self):
return 'Use cls() to clear the screen.'
def __call__(self, flush_scrollback=False):
print('\n', '-'*os.get_terminal_size()[0], '\n', sep='')
os.clear(flush_scrollback)

builtins.cls = ScreenClearer()
```

Of course I'm glossing over the hard part -- actually clearing the 
screen and/or scrollback.

I think that doing both is easy:

- on Windows: `os.system('cls')`

- on Posix: `os.system('clear')`

To *not* clear the scrollback is easy on modern Linuxes:

- `os.system('clear -x')`

but I don't know how you can recognise in advance whether it is 
supported or not. On terminals that support it, this should work:

- `print('\33[H\33[2J')`

but I have no idea how to avoid clearing the scrollback buffer on 
Windows, or other posix systems with unusual terminals.

Of course IDLE will require something different.

The ultimate fallback for clearing the visible screen but not the 
scrollback is just `print('\n'*os.get_terminal_size()[1])`.

So we have plenty of solutions for this, but none of them are platform 
independent, and picking the right option for your specific terminal may 
be tricky for the more unusual terminals.


I don't have access to a Windows machine to experiment, but I found 
these issues which may be relevant:

https://github.com/microsoft/terminal/issues/1305

https://github.com/microsoft/terminal/issues/1882



-- 
Steve
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MF5NJI3MWYKYCCRII6WNP7EOLJQHEE46/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Marco Sulla
Well, in terminals like bash, `clear` does not really delete the
previous input. It simply move the scroll so the first line of the
input is the current input.

Maybe the REPL can emulate this in some way.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/LQBOO75BLG4CCVHNIFNK5K752ZKOHKON/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Ethan Furman

On 10/13/20 4:46 PM, Steven D'Aprano wrote:


And I [clear my screen] frequently, in both Python and bash. Because I never
remember the name of the bash command to do it (cls or clear?), and
Python doesn't have one, I just hold down the Enter key for a couple of
seconds until there's no clutter visible.


I use `reset` -- particularly handy when you cat a binary file.

--
~Ethan~
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/4RQ4XQY6H23PXPZYIHK4GOAO4JE3YBUT/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Jonathan Crall
@Paul Moor, I agree with you. Personally, I'd rather not use it, and if it
was used in an importable module I'd claim it was bad practice.

But in general I don't think there is a right answer of if you *should *or
not. I think it is valid for personal preferences to vary here. If this is
something someone forgets to do a lot (and everyone has their own personal
quirks about what's hard/easy for them to remember), then it could be
annoying to the point where this feature could really help them.

But yes, in most cases I'd rather not use it, and I would get peeved if
someone's code they advertised as reusable used this (but then again I also
get peeved when people execute print statements at import time).



On Fri, Oct 16, 2020 at 5:02 PM Paul Moore  wrote:

> On Fri, 16 Oct 2020 at 20:43, Jonathan Crall  wrote:
> >
> > @Chris Angelico If you are more application focused, or trying to get a
> scientific result, and you don't care too much about the reusability of
> your scripts, then I can see the validity of this use case. But I would not
> want to install a module on pypi that made use of this. From a software
> perspective this is 100% bad practice, but from a practitioner perspective
> --- and there are a lot of practitioners that only use Python as a tool
> (like a DSL) --- I can see wanting it.
> >
> > So, that's the question: does the Python stdlib want to let you do this?
> Will the number of software engineers who use this incorrectly outweigh the
> number of people who seem to want this for a valid reason? I'm not sure
> what the answer is.
> >
> > FWIW executing `print('\x1b[H\x1b[2J\x1b[3J')` in my IPython terminal
> cleared the screen.
>
> Why would you want to put this in your script, so that you have no
> choice (short of editing the script) as to whether it happens? Surely
> better to clear your terminal from the command prompt *before* running
> your script? Yes, you can forget, but I'd rather forget occasionally
> than lose essential data because I ran a script that I'd forgotten has
> an os.clear() at the top...
>
> I suspect Guido's right, it's asked for often enough, and fiddly
> enough to write, that adding it is a net gain. But I'd be very
> unlikely to use it myself, and I'd strongly advise people against
> using it if asked.
>
> Paul
>


-- 
-Dr. Jon Crall (him)
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/L5UWOFF27IC4LBCQZ4SFQ26RLLDDNBPJ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Rob Cliffe via Python-ideas



On 16/10/2020 22:02, Paul Moore wrote:

On Fri, 16 Oct 2020 at 20:43, Jonathan Crall  wrote:

@Chris Angelico If you are more application focused, or trying to get a 
scientific result, and you don't care too much about the reusability of your 
scripts, then I can see the validity of this use case. But I would not want to 
install a module on pypi that made use of this. From a software perspective 
this is 100% bad practice, but from a practitioner perspective --- and there 
are a lot of practitioners that only use Python as a tool (like a DSL) --- I 
can see wanting it.

So, that's the question: does the Python stdlib want to let you do this? Will 
the number of software engineers who use this incorrectly outweigh the number 
of people who seem to want this for a valid reason? I'm not sure what the 
answer is.


Why is this the question?  Any feature can be misused.  That some users 
will misuse it is not IMHO a reason to deprive those users who will use 
it correctly.

Best wishes
Rob Cliffe
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ECBWVDLYJ54HOAKVLOCE6LBXGY462DXQ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Paul Moore
On Fri, 16 Oct 2020 at 20:43, Jonathan Crall  wrote:
>
> @Chris Angelico If you are more application focused, or trying to get a 
> scientific result, and you don't care too much about the reusability of your 
> scripts, then I can see the validity of this use case. But I would not want 
> to install a module on pypi that made use of this. From a software 
> perspective this is 100% bad practice, but from a practitioner perspective 
> --- and there are a lot of practitioners that only use Python as a tool (like 
> a DSL) --- I can see wanting it.
>
> So, that's the question: does the Python stdlib want to let you do this? Will 
> the number of software engineers who use this incorrectly outweigh the number 
> of people who seem to want this for a valid reason? I'm not sure what the 
> answer is.
>
> FWIW executing `print('\x1b[H\x1b[2J\x1b[3J')` in my IPython terminal cleared 
> the screen.

Why would you want to put this in your script, so that you have no
choice (short of editing the script) as to whether it happens? Surely
better to clear your terminal from the command prompt *before* running
your script? Yes, you can forget, but I'd rather forget occasionally
than lose essential data because I ran a script that I'd forgotten has
an os.clear() at the top...

I suspect Guido's right, it's asked for often enough, and fiddly
enough to write, that adding it is a net gain. But I'd be very
unlikely to use it myself, and I'd strongly advise people against
using it if asked.

Paul
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/6KBXBPS2SVVYZSL6FSM24YLHX6MGN2Y6/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Jonathan Crall
@Chris Angelico  If you are more application focused, or
trying to get a scientific result, and you don't care too much about the
reusability of your scripts, then I can see the validity of this use case.
But I would not want to install a module on pypi that made use of this.
>From a software perspective this is 100% bad practice, but from a
practitioner perspective --- and there are a lot of practitioners that only
use Python as a tool (like a DSL) --- I can see wanting it.

So, that's the question: does the Python stdlib want to let you do this?
Will the number of software engineers who use this incorrectly outweigh the
number of people who seem to want this for a valid reason? I'm not sure
what the answer is.

FWIW executing `print('\x1b[H\x1b[2J\x1b[3J')` in my IPython terminal
cleared the screen.

On Fri, Oct 16, 2020 at 2:45 PM Chris Angelico  wrote:

> On Sat, Oct 17, 2020 at 5:40 AM Jonathan Crall  wrote:
> >
> > I just want to point out that I can think of a valid use case for `clf`.
> I'm not sure if it was mentioned.
> >
> > In the case where you have a script that produces a lot of output, a
> common task might be scrolling to the beginning to check an output. If your
> screen was not fresh, and you had a lot of previous output (say from
> running the script multiple times), then it is hard to find the beginning
> unless you have previously cleared the screen.
> >
>
> This is exactly why I think this should NOT be made too easy. That's a
> perfect example of an attractive nuisance: instead of creating a
> divider (say, a half a dozen blank lines, or a row of hyphens with a
> blank or two each side), you're throwing away all information from the
> previous output, making it impossible to compare the two. Once your
> script has a clear-screen at the start of it, you lose the option to
> examine history, whereas a simple few blank lines would have a similar
> effect without losing anything.
>
> If it is added to the stdlib, I hope that it's buried away where
> people find it only if they're actually looking for it. There ARE
> valid use-cases, but there are far far more cases where it shouldn't
> be used.
>
> ChrisA
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/7BZX6GHHWZ4IIP5ITRYCRKKHDGCM3OVS/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
-Dr. Jon Crall (him)
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/HCHYR6ZXSRUWAMSJUG2HDZCVGHCT7MJ6/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Chris Angelico
On Sat, Oct 17, 2020 at 5:40 AM Jonathan Crall  wrote:
>
> I just want to point out that I can think of a valid use case for `clf`. I'm 
> not sure if it was mentioned.
>
> In the case where you have a script that produces a lot of output, a common 
> task might be scrolling to the beginning to check an output. If your screen 
> was not fresh, and you had a lot of previous output (say from running the 
> script multiple times), then it is hard to find the beginning unless you have 
> previously cleared the screen.
>

This is exactly why I think this should NOT be made too easy. That's a
perfect example of an attractive nuisance: instead of creating a
divider (say, a half a dozen blank lines, or a row of hyphens with a
blank or two each side), you're throwing away all information from the
previous output, making it impossible to compare the two. Once your
script has a clear-screen at the start of it, you lose the option to
examine history, whereas a simple few blank lines would have a similar
effect without losing anything.

If it is added to the stdlib, I hope that it's buried away where
people find it only if they're actually looking for it. There ARE
valid use-cases, but there are far far more cases where it shouldn't
be used.

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7BZX6GHHWZ4IIP5ITRYCRKKHDGCM3OVS/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Jonathan Crall
I just want to point out that I can think of a valid use case for `clf`.
I'm not sure if it was mentioned.

In the case where you have a script that produces a lot of output, a common
task might be scrolling to the beginning to check an output. If your screen
was not fresh, and you had a lot of previous output (say from running the
script multiple times), then it is hard to find the beginning unless you
have previously cleared the screen.

If you have cls, you can ensure that your big crazy
undergrad-programming-level script always clears the screen when it runs.
Maybe that helps you get your homework in on time. There is a task you
commonly do (clear the screen via cls or clear) programatically in python.

You may say: why are you not using logging? Well, perhaps --- because it
seems it is typically students who want to do this --- perhaps they don't
know how to do logging, or have doubts that they know how to do it
properly.

It seems that something like this might be better as a third party library,
given that it's more of a stdout + console specific thing. But on the other
hand this isn't much worse than `os.startfile` on windows.



On Fri, Oct 16, 2020 at 1:21 PM David Mertz  wrote:

> I agree with Guido here.  Although I really don't care about the
> capability myself, it feels like enough people do want a "clear screen"
> function... and from the discussion, in feels like there are a LOT of
> variations in how to do it across different operating systems, OS versions,
> terminals, shells, etc.
>
> Having a common interface of `os.clear()` that did whatever funny thing a
> particular environment needed would save some folks trouble.  Of course,
> I'm not certain how far it is possible to auto-detect the environment
> details within that function to "do the right thing" ... but probably there
> are clever hacks that get to 90% working.
>
> On Fri, Oct 16, 2020 at 1:03 PM Rob Cliffe via Python-ideas <
> python-ideas@python.org> wrote:
>
>>
>>
>> On 16/10/2020 13:55, Chris Angelico wrote:
>> > On Fri, Oct 16, 2020 at 11:08 PM Rob Cliffe 
>> wrote:
>> >>
>> >>
>> >> On 16/10/2020 11:59, Chris Angelico wrote:
>> >>> On Fri, Oct 16, 2020 at 8:21 PM Rob Cliffe via Python-ideas
>> >>>  wrote:
>> 
>>  On 13/10/2020 23:35, Guido van Rossum wrote:
>> > Can one of the educators on the list explain why this is such a
>> > commonly required feature? I literally never feel the need to clear
>> my
>> > screen -- but I've seen this requested quite a few times in various
>> > forms, often as a bug report "IDLE does not support CLS". I presume
>> > that this is a common thing in other programming environments for
>> > beginners -- even C++ (given that it was mentioned). Maybe it's a
>> > thing that command-line users on Windows are told to do frequently?
>> > What am I missing that students want to do frequently? Is it a
>> > holdover from the DOS age?
>> >
>>  Sometimes I want a program that displays (more than 1 line of)
>> real-time
>>  information in a Windows CMD box and refreshes it every few seconds
>>  (e.g. progress displays, monitoring open
>>  files/locks/connections/downloads etc.).  It is natural to clear the
>>  screen and display the updated information.
>> >>> Natural perhaps, but ugly. Much better to reposition the cursor and
>> >>> overwrite the previous text, with "clear to end of line" as required;
>> >>> that way, you avoid flicker.
>> >>>
>> >>> C
>> >> I do precisely that in many of my programs for e.g. single-line
>> progress
>> >> displays.
>> >> But for multi-line output I don't know of any way to move the cursor
>> >> back up.
>> >> I work in Windows 10.
>> > Try \x1b[A to move up a line, should work.
>> >
>> > ChrisA
>> Thanks Chris, but no luck.  It just echoes it, with the \x1b (Escape)
>> echoed as a character that looks like a question mark inside a box.
>> Earlier I did try googling for ways of moving the cursor, but almost all
>> I found was ways of moving the *mouse* cursor, and the rest was
>> irrelevant.
>> Rob Cliffe
>> > ___
>> > Python-ideas mailing list -- python-ideas@python.org
>> > To unsubscribe send an email to python-ideas-le...@python.org
>> > https://mail.python.org/mailman3/lists/python-ideas.python.org/
>> > Message archived at
>> https://mail.python.org/archives/list/python-ideas@python.org/message/5VZGBRIEW5UPQ6VCYQXC3UUNNHQXNFRB/
>> > Code of Conduct: http://python.org/psf/codeofconduct/
>> ___
>> Python-ideas mailing list -- python-ideas@python.org
>> To unsubscribe send an email to python-ideas-le...@python.org
>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>> Message archived at
>> https://mail.python.org/archives/list/python-ideas@python.org/message/5SBLJZAT3CH35ILXLSCLX5R62BQX3FQE/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
>
> --
> The dead increasingly dominate and st

[Python-ideas] Re: New feature

2020-10-16 Thread David Mertz
I agree with Guido here.  Although I really don't care about the capability
myself, it feels like enough people do want a "clear screen" function...
and from the discussion, in feels like there are a LOT of variations in how
to do it across different operating systems, OS versions, terminals,
shells, etc.

Having a common interface of `os.clear()` that did whatever funny thing a
particular environment needed would save some folks trouble.  Of course,
I'm not certain how far it is possible to auto-detect the environment
details within that function to "do the right thing" ... but probably there
are clever hacks that get to 90% working.

On Fri, Oct 16, 2020 at 1:03 PM Rob Cliffe via Python-ideas <
python-ideas@python.org> wrote:

>
>
> On 16/10/2020 13:55, Chris Angelico wrote:
> > On Fri, Oct 16, 2020 at 11:08 PM Rob Cliffe 
> wrote:
> >>
> >>
> >> On 16/10/2020 11:59, Chris Angelico wrote:
> >>> On Fri, Oct 16, 2020 at 8:21 PM Rob Cliffe via Python-ideas
> >>>  wrote:
> 
>  On 13/10/2020 23:35, Guido van Rossum wrote:
> > Can one of the educators on the list explain why this is such a
> > commonly required feature? I literally never feel the need to clear
> my
> > screen -- but I've seen this requested quite a few times in various
> > forms, often as a bug report "IDLE does not support CLS". I presume
> > that this is a common thing in other programming environments for
> > beginners -- even C++ (given that it was mentioned). Maybe it's a
> > thing that command-line users on Windows are told to do frequently?
> > What am I missing that students want to do frequently? Is it a
> > holdover from the DOS age?
> >
>  Sometimes I want a program that displays (more than 1 line of)
> real-time
>  information in a Windows CMD box and refreshes it every few seconds
>  (e.g. progress displays, monitoring open
>  files/locks/connections/downloads etc.).  It is natural to clear the
>  screen and display the updated information.
> >>> Natural perhaps, but ugly. Much better to reposition the cursor and
> >>> overwrite the previous text, with "clear to end of line" as required;
> >>> that way, you avoid flicker.
> >>>
> >>> C
> >> I do precisely that in many of my programs for e.g. single-line progress
> >> displays.
> >> But for multi-line output I don't know of any way to move the cursor
> >> back up.
> >> I work in Windows 10.
> > Try \x1b[A to move up a line, should work.
> >
> > ChrisA
> Thanks Chris, but no luck.  It just echoes it, with the \x1b (Escape)
> echoed as a character that looks like a question mark inside a box.
> Earlier I did try googling for ways of moving the cursor, but almost all
> I found was ways of moving the *mouse* cursor, and the rest was irrelevant.
> Rob Cliffe
> > ___
> > Python-ideas mailing list -- python-ideas@python.org
> > To unsubscribe send an email to python-ideas-le...@python.org
> > https://mail.python.org/mailman3/lists/python-ideas.python.org/
> > Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/5VZGBRIEW5UPQ6VCYQXC3UUNNHQXNFRB/
> > Code of Conduct: http://python.org/psf/codeofconduct/
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/5SBLJZAT3CH35ILXLSCLX5R62BQX3FQE/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/3O4AQ2GX5UXYOLULBKOX5ZVSF2QN3KMS/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Rob Cliffe via Python-ideas



On 16/10/2020 13:55, Chris Angelico wrote:

On Fri, Oct 16, 2020 at 11:08 PM Rob Cliffe  wrote:



On 16/10/2020 11:59, Chris Angelico wrote:

On Fri, Oct 16, 2020 at 8:21 PM Rob Cliffe via Python-ideas
 wrote:


On 13/10/2020 23:35, Guido van Rossum wrote:

Can one of the educators on the list explain why this is such a
commonly required feature? I literally never feel the need to clear my
screen -- but I've seen this requested quite a few times in various
forms, often as a bug report "IDLE does not support CLS". I presume
that this is a common thing in other programming environments for
beginners -- even C++ (given that it was mentioned). Maybe it's a
thing that command-line users on Windows are told to do frequently?
What am I missing that students want to do frequently? Is it a
holdover from the DOS age?


Sometimes I want a program that displays (more than 1 line of) real-time
information in a Windows CMD box and refreshes it every few seconds
(e.g. progress displays, monitoring open
files/locks/connections/downloads etc.).  It is natural to clear the
screen and display the updated information.

Natural perhaps, but ugly. Much better to reposition the cursor and
overwrite the previous text, with "clear to end of line" as required;
that way, you avoid flicker.

C

I do precisely that in many of my programs for e.g. single-line progress
displays.
But for multi-line output I don't know of any way to move the cursor
back up.
I work in Windows 10.

Try \x1b[A to move up a line, should work.

ChrisA
Thanks Chris, but no luck.  It just echoes it, with the \x1b (Escape) 
echoed as a character that looks like a question mark inside a box.
Earlier I did try googling for ways of moving the cursor, but almost all 
I found was ways of moving the *mouse* cursor, and the rest was irrelevant.

Rob Cliffe

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/5VZGBRIEW5UPQ6VCYQXC3UUNNHQXNFRB/
Code of Conduct: http://python.org/psf/codeofconduct/

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/5SBLJZAT3CH35ILXLSCLX5R62BQX3FQE/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Eryk Sun
On 10/16/20, Barry Scott  wrote:
>
> I find that you have to do this to turn on ANSI processing in CMD.EXE on
> Window 10 and I assume earlier Windwows as wel:

You mean the console-session host (conhost.exe). This has nothing to
do with the CMD shell. People often confuse CLI shells (CMD,
PowerShell, bash) with the console/terminal that they use for standard
I/O.

Virtual Terminal mode is supported by the new console in Windows 10 --
not in earlier versions of Windows and not with the legacy console in
Windows 10. If you need to support ANSI sequences with the legacy
console host, consider using a third-party library such as colorama.

You can enable VT mode by default for regular console sessions (i.e.
not headless sessions such as under Windows Terminal, for which it's
always enabled) by setting a DWORD value of 1 named
"VirtualTerminalLevel" in the registry key "HKCU\Console".

> import ctypes
> kernel32 = ctypes.windll.kernel32
> # turn on the console ANSI colour handling
> kernel32.SetConsoleMode( kernel32.GetStdHandle( -11 ), 7 )

You should enable the flag in the current mode value and implement
error handling:

import ctypes
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)

STD_OUTPUT_HANDLE = -11
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
INVALID_HANDLE_VALUE = ctypes.c_void_p(-1).value

kernel32.GetStdHandle.restype = ctypes.c_void_p

hstdout = kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
if hstdout == INVALID_HANDLE_VALUE:
raise ctypes.WinError(ctypes.get_last_error())

mode = ctypes.c_ulong()
if not kernel32.GetConsoleMode(hstdout, ctypes.byref(mode)):
raise ctypes.WinError(ctypes.get_last_error())

mode.value |= ENABLE_VIRTUAL_TERMINAL_PROCESSING
if not kernel32.SetConsoleMode(hstdout, mode):
raise ctypes.WinError(ctypes.get_last_error())
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/UHIZNALCL7UGX5LXJACHHKOHMUMXACKN/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Barry Scott



> On 16 Oct 2020, at 14:44, Rob Cliffe via Python-ideas 
>  wrote:
> 
> 
> 
> On 16/10/2020 13:55, Chris Angelico wrote:
>> 
>>> I do precisely that in many of my programs for e.g. single-line progress
>>> displays.
>>> But for multi-line output I don't know of any way to move the cursor
>>> back up.
>>> I work in Windows 10.
>> Try \x1b[A to move up a line, should work.

I find that you have to do this to turn on ANSI processing in CMD.EXE on Window 
10
and I assume earlier Windwows as wel:

import ctypes
kernel32 = ctypes.windll.kernel32
# turn on the console ANSI colour handling
kernel32.SetConsoleMode( kernel32.GetStdHandle( -11 ), 7 )

Now you can use escape sequences:

print('\x1b[31m Hello in red \x1b[m')

Given the need to call WIN32 APIs to get this working making this part
of stdlib would help a lot.

Barry


>> 
>> ChrisA
> Got it working!  The answer is
>  \x1b[1A
> Thanks for the pointer!
> Rob Cliffe
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/message/B3HVTOIQBA6YGCK4TJRLQW4FTBF2IXAQ/
> Code of Conduct: http://python.org/psf/codeofconduct/
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ZJVCAOCUUFCVWVPJQEUROUX5U4TUF2K4/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Rob Cliffe via Python-ideas



On 16/10/2020 13:55, Chris Angelico wrote:



I do precisely that in many of my programs for e.g. single-line progress
displays.
But for multi-line output I don't know of any way to move the cursor
back up.
I work in Windows 10.

Try \x1b[A to move up a line, should work.

ChrisA

Got it working!  The answer is
 \x1b[1A
Thanks for the pointer!
Rob Cliffe
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/B3HVTOIQBA6YGCK4TJRLQW4FTBF2IXAQ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Joao S. O. Bueno
On Fri, 16 Oct 2020 at 08:00, Chris Angelico  wrote:

> On Fri, Oct 16, 2020 at 8:21 PM Rob Cliffe via Python-ideas
>  wrote:
> >
> >
> >
> > On 13/10/2020 23:35, Guido van Rossum wrote:
> > > Can one of the educators on the list explain why this is such a
> > > commonly required feature? I literally never feel the need to clear my
> > > screen -- but I've seen this requested quite a few times in various
> > > forms, often as a bug report "IDLE does not support CLS". I presume
> > > that this is a common thing in other programming environments for
> > > beginners -- even C++ (given that it was mentioned). Maybe it's a
> > > thing that command-line users on Windows are told to do frequently?
> > > What am I missing that students want to do frequently? Is it a
> > > holdover from the DOS age?
> > >
> > Sometimes I want a program that displays (more than 1 line of) real-time
> > information in a Windows CMD box and refreshes it every few seconds
> > (e.g. progress displays, monitoring open
> > files/locks/connections/downloads etc.).  It is natural to clear the
> > screen and display the updated information.
>
> Natural perhaps, but ugly. Much better to reposition the cursor and
> overwrite the previous text, with "clear to end of line" as required;
> that way, you avoid flicker.
>

Let me tell you what is ugly -
people doing `os.system("cls")` in otherwise what would otherwise
be a perfect multiplatform script.

And while we may question why people want this feature, fact is it is
requested
time and time again - and I'd find rather useful having it around when
answering
questions instead of having to say: "ok, if are on Mac or Linux, do
`print("\x1b[H")`, if you
are on windows `pip install colorama ...`.

Check for the occurrences of `os.system('cls')` in the Portuguese version
of stackoverflow, for example:
https://pt.stackoverflow.com/search?q=is%3Aanswer+os.system%28%27cls%27%29




> ChrisA
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/NA2NOM3EYQXYRCWN373SH3PV6PARLZ7H/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EJR32XUFFWB2YOKUSEDDKZMXV4NO3TEP/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Chris Angelico
On Fri, Oct 16, 2020 at 11:08 PM Rob Cliffe  wrote:
>
>
>
> On 16/10/2020 11:59, Chris Angelico wrote:
> > On Fri, Oct 16, 2020 at 8:21 PM Rob Cliffe via Python-ideas
> >  wrote:
> >>
> >>
> >> On 13/10/2020 23:35, Guido van Rossum wrote:
> >>> Can one of the educators on the list explain why this is such a
> >>> commonly required feature? I literally never feel the need to clear my
> >>> screen -- but I've seen this requested quite a few times in various
> >>> forms, often as a bug report "IDLE does not support CLS". I presume
> >>> that this is a common thing in other programming environments for
> >>> beginners -- even C++ (given that it was mentioned). Maybe it's a
> >>> thing that command-line users on Windows are told to do frequently?
> >>> What am I missing that students want to do frequently? Is it a
> >>> holdover from the DOS age?
> >>>
> >> Sometimes I want a program that displays (more than 1 line of) real-time
> >> information in a Windows CMD box and refreshes it every few seconds
> >> (e.g. progress displays, monitoring open
> >> files/locks/connections/downloads etc.).  It is natural to clear the
> >> screen and display the updated information.
> > Natural perhaps, but ugly. Much better to reposition the cursor and
> > overwrite the previous text, with "clear to end of line" as required;
> > that way, you avoid flicker.
> >
> > C
> I do precisely that in many of my programs for e.g. single-line progress
> displays.
> But for multi-line output I don't know of any way to move the cursor
> back up.
> I work in Windows 10.

Try \x1b[A to move up a line, should work.

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/5VZGBRIEW5UPQ6VCYQXC3UUNNHQXNFRB/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Rob Cliffe via Python-ideas




On 16/10/2020 11:59, Chris Angelico wrote:

On Fri, Oct 16, 2020 at 8:21 PM Rob Cliffe via Python-ideas
 wrote:



On 13/10/2020 23:35, Guido van Rossum wrote:

Can one of the educators on the list explain why this is such a
commonly required feature? I literally never feel the need to clear my
screen -- but I've seen this requested quite a few times in various
forms, often as a bug report "IDLE does not support CLS". I presume
that this is a common thing in other programming environments for
beginners -- even C++ (given that it was mentioned). Maybe it's a
thing that command-line users on Windows are told to do frequently?
What am I missing that students want to do frequently? Is it a
holdover from the DOS age?


Sometimes I want a program that displays (more than 1 line of) real-time
information in a Windows CMD box and refreshes it every few seconds
(e.g. progress displays, monitoring open
files/locks/connections/downloads etc.).  It is natural to clear the
screen and display the updated information.

Natural perhaps, but ugly. Much better to reposition the cursor and
overwrite the previous text, with "clear to end of line" as required;
that way, you avoid flicker.

C
I do precisely that in many of my programs for e.g. single-line progress 
displays.
But for multi-line output I don't know of any way to move the cursor 
back up.

I work in Windows 10.
Rob Cliffe
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/LU76AX5APOCEZVNN4XN5LTMLSXRJOFDP/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Chris Angelico
On Fri, Oct 16, 2020 at 8:21 PM Rob Cliffe via Python-ideas
 wrote:
>
>
>
> On 13/10/2020 23:35, Guido van Rossum wrote:
> > Can one of the educators on the list explain why this is such a
> > commonly required feature? I literally never feel the need to clear my
> > screen -- but I've seen this requested quite a few times in various
> > forms, often as a bug report "IDLE does not support CLS". I presume
> > that this is a common thing in other programming environments for
> > beginners -- even C++ (given that it was mentioned). Maybe it's a
> > thing that command-line users on Windows are told to do frequently?
> > What am I missing that students want to do frequently? Is it a
> > holdover from the DOS age?
> >
> Sometimes I want a program that displays (more than 1 line of) real-time
> information in a Windows CMD box and refreshes it every few seconds
> (e.g. progress displays, monitoring open
> files/locks/connections/downloads etc.).  It is natural to clear the
> screen and display the updated information.

Natural perhaps, but ugly. Much better to reposition the cursor and
overwrite the previous text, with "clear to end of line" as required;
that way, you avoid flicker.

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/NA2NOM3EYQXYRCWN373SH3PV6PARLZ7H/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-16 Thread Rob Cliffe via Python-ideas



On 13/10/2020 23:35, Guido van Rossum wrote:
Can one of the educators on the list explain why this is such a 
commonly required feature? I literally never feel the need to clear my 
screen -- but I've seen this requested quite a few times in various 
forms, often as a bug report "IDLE does not support CLS". I presume 
that this is a common thing in other programming environments for 
beginners -- even C++ (given that it was mentioned). Maybe it's a 
thing that command-line users on Windows are told to do frequently? 
What am I missing that students want to do frequently? Is it a 
holdover from the DOS age?


Sometimes I want a program that displays (more than 1 line of) real-time 
information in a Windows CMD box and refreshes it every few seconds 
(e.g. progress displays, monitoring open 
files/locks/connections/downloads etc.).  It is natural to clear the 
screen and display the updated information.

Rob Cliffe
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/2WYRJJMBDTJ2KGMFE33USITIF5CCRIR2/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-15 Thread Guido van Rossum
I searched my own email archives and found that this is indeed frequently
requested for IDLE. For example, Raymond Hettinger filed *two* different
bug reports about it on behalf of his students, both closed as duplicates
of https://bugs.python.org/issue6143, which has been open with frequent
discussion since 2009 (!).

I also found several other requests for this, e.g. one from this August in
idle-dev, one from August 2018 in core-mentorship, another from August 2017
in idle-dev, and a long python-ideas thread from October 2016. (What is it
with August? I really do think this is a "new student" thing...)

One reason it's important for IDLE is that IDLE's shell window slows down
as its buffer gets longer, and it cannot easily be emptied (it's
uneditable). And in IDLE, none of the solutions that print escape sequences
work, because IDLE's shell window is not a terminal emulator.

Outside IDLE, the main problem seems to be that few people know enough to
figure out it's a simple escape sequence, and the system commands vary by
system (on my Mac it's "clear" and it prints ESC [ H ESC [ 2 J).

Let's add a function os.clear(), and perhaps IDLE (or some enterprising
IDLE hacker) can monkey-patch that to do whatever makes IDLE's shell reset.

On Thu, Oct 15, 2020 at 4:52 PM Mike Miller 
wrote:

>
> On 2020-10-13 15:35, Guido van Rossum wrote:
> > Can one of the educators on the list explain why this is such a commonly
> > required feature? I literally never feel the need to clear my screen --
> but I've
> > seen this requested quite a few times in various forms, often as a bug
> report
> > "IDLE does not support CLS". I presume that this is a common thing in
> other
> > programming environments for beginners -- even C++ (given that it was
> > mentioned). Maybe it's a thing that command-line users on Windows are
> told to do
> > frequently? What am I missing that students want to do frequently? Is it
> a
> > holdover from the DOS age?
>
>
> Not Windows specific, no.  I've never thought of it as beginner-specific
> either.
>   It's an ANSI standard terminal feature that existed beforehand, right?
> My
> knowledge before that is limited.
>
> Why?  It's mostly about focus I suppose.  Commonly used when switching to
> a new
> task, logging out for security reasons, or perhaps when there are several
> terminals on screen at once which have not been used in a while.  Stale
> output
> is no longer relevant and becomes visual clutter.
>
> I use it most often when there's a ton of debug log messages from a
> service.
> This makes the scrollbar more useful because (cleared beforehand) output
> now
> represents 100% of the scrollback when needing to pinpoint a problem at a
> particular time.
>
> So I believe there's room for terminal functionality in Python between
> "dumb"
> output and a full screen TUI, such as would be used in a wizard-type
> program, or
> clearing before printing a current status.
>
> In terms of common use, I'd guess it has something to do with one's
> personality.
>   What does your desk look like right now?  Piles of papers everywhere, or
> neat
> as a pin minimalism?  A spectrum of folks exist and are good contributors.
>
> A few other folks commented that they don't use it.  I've personally never
> used
> a number of features in the stdlib either.  However, this one is simple to
> implement and commonly expected.
>
> -Mike
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/6WU7UHCMS5BEX3ZVY7U55BUNHKJQ6M7N/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EKK6AH6H5MXOSLBTDZTJX3CXCHS3FVME/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-15 Thread Mike Miller



On 2020-10-13 15:35, Guido van Rossum wrote:
Can one of the educators on the list explain why this is such a commonly 
required feature? I literally never feel the need to clear my screen -- but I've 
seen this requested quite a few times in various forms, often as a bug report 
"IDLE does not support CLS". I presume that this is a common thing in other 
programming environments for beginners -- even C++ (given that it was 
mentioned). Maybe it's a thing that command-line users on Windows are told to do 
frequently? What am I missing that students want to do frequently? Is it a 
holdover from the DOS age?



Not Windows specific, no.  I've never thought of it as beginner-specific either. 
 It's an ANSI standard terminal feature that existed beforehand, right?  My 
knowledge before that is limited.


Why?  It's mostly about focus I suppose.  Commonly used when switching to a new 
task, logging out for security reasons, or perhaps when there are several 
terminals on screen at once which have not been used in a while.  Stale output 
is no longer relevant and becomes visual clutter.


I use it most often when there's a ton of debug log messages from a service. 
This makes the scrollbar more useful because (cleared beforehand) output now 
represents 100% of the scrollback when needing to pinpoint a problem at a 
particular time.


So I believe there's room for terminal functionality in Python between "dumb" 
output and a full screen TUI, such as would be used in a wizard-type program, or 
clearing before printing a current status.


In terms of common use, I'd guess it has something to do with one's personality. 
 What does your desk look like right now?  Piles of papers everywhere, or neat 
as a pin minimalism?  A spectrum of folks exist and are good contributors.


A few other folks commented that they don't use it.  I've personally never used 
a number of features in the stdlib either.  However, this one is simple to 
implement and commonly expected.


-Mike
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/6WU7UHCMS5BEX3ZVY7U55BUNHKJQ6M7N/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-14 Thread ankith abhayan
The 2nd one.
Regards

On Wed, 14 Oct 2020, 5:47 am Steven D'Aprano,  wrote:

> Hello Ankith,
>
>
> On Tue, Oct 13, 2020 at 11:37:25AM +0530, ankith abhayan wrote:
> > Hi,
> > I would like to request a new feature that allows you to clear the
> console
> > screen.
> > Like in c++, the CLS function
>
>
> Can you be specific? I can think of at least three behaviours:
>
> 1. Move all existing console output off-screen, displaying a fresh
> prompt at the top of the window. Existing output is still available, but
> you have to scroll up to see it.
>
> 2. Not just hide the existing output, but remove it from the scrollback
> buffer.
>
> 3. Like 2 above, but also force the terminal settings back to their
> default state (useful if you have accidentally printed terminal control
> codes that have messed up the settings).
>
>
> On Linux, I think that option 3 is best left for the terminal
> application. There is usually a "Reset" command that will do that. I
> don't know what Mac and Windows offer, but either way, that's probably
> something best left for the console or terminal application itself.
>
>
>
> --
> Steve
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/IITZGD5KE4RPZBRY2AIADPSK5QNT2QZS/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SSTU5UEFVVW75ZIRN6NGPK6KCPQASDZV/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-14 Thread M.-A. Lemburg
On 14.10.2020 00:35, Guido van Rossum wrote:
> Can one of the educators on the list explain why this is such a commonly
> required feature? I literally never feel the need to clear my screen -- but 
> I've
> seen this requested quite a few times in various forms, often as a bug report
> "IDLE does not support CLS". I presume that this is a common thing in other
> programming environments for beginners -- even C++ (given that it was
> mentioned). Maybe it's a thing that command-line users on Windows are told to 
> do
> frequently? What am I missing that students want to do frequently? Is it a
> holdover from the DOS age?

I often use clear or Ctrl-L in terminals when I'm preparing demos
or screensharing.

Given that we already have os.get_terminal_size(), perhaps adding
a helper os.clear_terminal() would make sense, along the lines of

https://man7.org/linux/man-pages/man1/clear.1.html

I don't remember ever having a need for this in Python, though. When
I do have such needs to drive the terminal to get e.g. bold output,
I usually use ANSI escape codes:

https://en.wikipedia.org/wiki/ANSI_escape_code

but then I normally write scripts for Unix, not other platforms, so
perhaps having a cross-platform variant would be useful.

In dialog driven scripts, it does make sense to clear the screen to
get attention from the user for requesting input. This was also
standard when terminals were being used as the main UI for applications
in the vt100 days. I guess today, most people use the endless
scrolling approach, so it's less comon and where it is
needed, you have ncursus or other terminal UI managers take care
of this for you.

> On Tue, Oct 13, 2020 at 11:25 AM Mike Miller  > wrote:
> 
> 
> On 2020-10-13 06:19, Stestagg wrote:
> > For example, the pypi `console` library provides a method:
> `console.sc.reset()`
> > that behaves similarly to `CLS` on windows and also appears to be fairly
> > reliable cross-platform.
> 
> 
> Yes, there is more to it than appears at first glance.  There is 
> resetting the
> terminal, clearing the currently visible screen, and/or the scrollback
> buffer as
> well.
> 
> The legacy Windows console has another limitation in that I don't believe 
> it
> has
> a single API call to clear the whole thing.  One must iterate over the 
> whole
> buffer and write spaces to each cell, or some similar craziness.  That's 
> why
> even folks writing C++ just punt and do a system("cls") instead.
> 
> With the mentioned lib console, the example above prints the ANSI codes 
> to do a
> terminal reset, and while that works widely these days, it should not be 
> the
> first choice.  It would be better to use the cross-platform wrapper
> functions in
> the console.utils module, either:
> 
>      # A DOS-like reset, clears screen and scrollback, also aliased to 
> cls()
>      reset_terminal()
> 
>      # A Unix-like clear, configurable via param, and aliased to clear()
>      clear_screen()
> 
> -Mike
> ___
> Python-ideas mailing list -- python-ideas@python.org
> 
> To unsubscribe send an email to python-ideas-le...@python.org
> 
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> 
> https://mail.python.org/archives/list/python-ideas@python.org/message/MX54AOXMYJHGRVOO2XW3J7JWHQDDUKPQ/
> Code of Conduct: http://python.org/psf/codeofconduct/
> 
> 
> 
> -- 
> --Guido van Rossum (python.org/~guido )
> /Pronouns: he/him //(why is my pronoun here?)/
> 
> 
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/message/J65P6UELD4RSSCSMAFYF52WADURHX2HL/
> Code of Conduct: http://python.org/psf/codeofconduct/
> 

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Oct 14 2020)
>>> Python Projects, Coaching and Support ...https://www.egenix.com/
>>> Python Product Development ...https://consulting.egenix.com/


::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   https://www.egenix.com/company/contact/
 https://www.malemburg.com/
___

[Python-ideas] Re: New feature

2020-10-13 Thread MRAB

On 2020-10-14 00:46, Steven D'Aprano wrote:

On Tue, Oct 13, 2020 at 03:35:58PM -0700, Guido van Rossum wrote:


Can one of the educators on the list explain why this is such a commonly
required feature? I literally never feel the need to clear my screen -- but
I've seen this requested quite a few times in various forms, often as a bug
report "IDLE does not support CLS". I presume that this is a common thing
in other programming environments for beginners -- even C++ (given that it
was mentioned). Maybe it's a thing that command-line users on Windows are
told to do frequently? What am I missing that students want to do
frequently? Is it a holdover from the DOS age?


I think it's a personal preference to remove the visible clutter from
the screen without going so far as to exit the interpreter and start a
new session.

And I do it frequently, in both Python and bash. Because I never
remember the name of the bash command to do it (cls or clear?), and
Python doesn't have one, I just hold down the Enter key for a couple of
seconds until there's no clutter visible.

(I just tried it in bash now, and it is spelled "clear", and it clears
the scrollback buffer as well as just clearing the visible clutter on
the screen.)

Oh, apparently Ctrl-L works too. I don't know if that's a feature of my
terminal or of the Python interpreter.

Historically, Ctrl+L is the Form Feed control character. I remember the 
the BBC Micro supporting it.



There's supposed to be a magic escape sequence that will clear the
screen when printed, if your terminal supports it, but I never remember
that either. Let me look it up...

 print("\x1b[H\x1b[2J")

seems to work.



___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VP2RIJW5BOXENROVFAY5UMFCDGXD7YB3/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-13 Thread Steven D'Aprano
Hello Ankith,


On Tue, Oct 13, 2020 at 11:37:25AM +0530, ankith abhayan wrote:
> Hi,
> I would like to request a new feature that allows you to clear the console
> screen.
> Like in c++, the CLS function


Can you be specific? I can think of at least three behaviours:

1. Move all existing console output off-screen, displaying a fresh 
prompt at the top of the window. Existing output is still available, but 
you have to scroll up to see it.

2. Not just hide the existing output, but remove it from the scrollback 
buffer.

3. Like 2 above, but also force the terminal settings back to their 
default state (useful if you have accidentally printed terminal control 
codes that have messed up the settings).


On Linux, I think that option 3 is best left for the terminal 
application. There is usually a "Reset" command that will do that. I 
don't know what Mac and Windows offer, but either way, that's probably 
something best left for the console or terminal application itself.



-- 
Steve
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/IITZGD5KE4RPZBRY2AIADPSK5QNT2QZS/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-13 Thread Michael Smith
I occasionally find it useful to clear the screen when doing
demos/presentations. I think the case for it is clear (hah) enough based on
its long history and presence in many terminal emulators. But then again,
the terminals I use and readline support it already, so I don't need python
repl  to do it for me.

+1 on having it. -1 on doing it in Python, per se. net +0.

On Tue, Oct 13, 2020 at 19:12 David Mertz  wrote:

> I teach a lot.  But it's adults, and ones who have at least a little bit
> of programming experience (perhaps in a different language, but something).
>
> I've never had anyone request a "clear screen" command.  Of course, I
> usually use Jupyter notebooks for teaching, so I'm not sure what that would
> mean there anyway.  But it definitely feels like a UI thing, not a PL
> thing.  About 30 seconds ago, I typed `%clear` in IPython... I'm not
> certain it is the first time I've ever done so, but quite likely.  It was
> amazing, my screen was cleared :-).
>
> On Tue, Oct 13, 2020 at 6:38 PM Guido van Rossum  wrote:
>
>> Can one of the educators on the list explain why this is such a commonly
>> required feature? I literally never feel the need to clear my screen -- but
>> I've seen this requested quite a few times in various forms, often as a bug
>> report "IDLE does not support CLS". I presume that this is a common thing
>> in other programming environments for beginners -- even C++ (given that it
>> was mentioned). Maybe it's a thing that command-line users on Windows are
>> told to do frequently? What am I missing that students want to do
>> frequently? Is it a holdover from the DOS age?
>>
>> On Tue, Oct 13, 2020 at 11:25 AM Mike Miller 
>> wrote:
>>
>>>
>>> On 2020-10-13 06:19, Stestagg wrote:
>>> > For example, the pypi `console` library provides a method:
>>> `console.sc.reset()`
>>> > that behaves similarly to `CLS` on windows and also appears to be
>>> fairly
>>> > reliable cross-platform.
>>>
>>>
>>> Yes, there is more to it than appears at first glance.  There is
>>> resetting the
>>> terminal, clearing the currently visible screen, and/or the scrollback
>>> buffer as
>>> well.
>>>
>>> The legacy Windows console has another limitation in that I don't
>>> believe it has
>>> a single API call to clear the whole thing.  One must iterate over the
>>> whole
>>> buffer and write spaces to each cell, or some similar craziness.  That's
>>> why
>>> even folks writing C++ just punt and do a system("cls") instead.
>>>
>>> With the mentioned lib console, the example above prints the ANSI codes
>>> to do a
>>> terminal reset, and while that works widely these days, it should not be
>>> the
>>> first choice.  It would be better to use the cross-platform wrapper
>>> functions in
>>> the console.utils module, either:
>>>
>>>  # A DOS-like reset, clears screen and scrollback, also aliased to
>>> cls()
>>>  reset_terminal()
>>>
>>>  # A Unix-like clear, configurable via param, and aliased to clear()
>>>  clear_screen()
>>>
>>> -Mike
>>> ___
>>> Python-ideas mailing list -- python-ideas@python.org
>>> To unsubscribe send an email to python-ideas-le...@python.org
>>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>>> Message archived at
>>> https://mail.python.org/archives/list/python-ideas@python.org/message/MX54AOXMYJHGRVOO2XW3J7JWHQDDUKPQ/
>>> Code of Conduct: http://python.org/psf/codeofconduct/
>>>
>>
>>
>> --
>> --Guido van Rossum (python.org/~guido)
>> *Pronouns: he/him **(why is my pronoun here?)*
>> 
>> ___
>> Python-ideas mailing list -- python-ideas@python.org
>> To unsubscribe send an email to python-ideas-le...@python.org
>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>> Message archived at
>> https://mail.python.org/archives/list/python-ideas@python.org/message/J65P6UELD4RSSCSMAFYF52WADURHX2HL/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
>
> --
> The dead increasingly dominate and strangle both the living and the
> not-yet born.  Vampiric capital and undead corporate persons abuse
> the lives and control the thoughts of homo faber. Ideas, once born,
> become abortifacients against new conceptions.
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/Q6NTJLEPOTULRKE6WKJGXG4W7NMST7VU/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Messag

[Python-ideas] Re: New feature

2020-10-13 Thread Steven D'Aprano
On Tue, Oct 13, 2020 at 03:35:58PM -0700, Guido van Rossum wrote:

> Can one of the educators on the list explain why this is such a commonly
> required feature? I literally never feel the need to clear my screen -- but
> I've seen this requested quite a few times in various forms, often as a bug
> report "IDLE does not support CLS". I presume that this is a common thing
> in other programming environments for beginners -- even C++ (given that it
> was mentioned). Maybe it's a thing that command-line users on Windows are
> told to do frequently? What am I missing that students want to do
> frequently? Is it a holdover from the DOS age?

I think it's a personal preference to remove the visible clutter from 
the screen without going so far as to exit the interpreter and start a 
new session.

And I do it frequently, in both Python and bash. Because I never 
remember the name of the bash command to do it (cls or clear?), and 
Python doesn't have one, I just hold down the Enter key for a couple of 
seconds until there's no clutter visible.

(I just tried it in bash now, and it is spelled "clear", and it clears 
the scrollback buffer as well as just clearing the visible clutter on 
the screen.)

Oh, apparently Ctrl-L works too. I don't know if that's a feature of my 
terminal or of the Python interpreter.

There's supposed to be a magic escape sequence that will clear the 
screen when printed, if your terminal supports it, but I never remember 
that either. Let me look it up... 

print("\x1b[H\x1b[2J")

seems to work.


-- 
Steve
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/I7SZOAD54SZ264Q7QNM7HO2YMD3QMX5E/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-13 Thread David Mertz
I teach a lot.  But it's adults, and ones who have at least a little bit of
programming experience (perhaps in a different language, but something).

I've never had anyone request a "clear screen" command.  Of course, I
usually use Jupyter notebooks for teaching, so I'm not sure what that would
mean there anyway.  But it definitely feels like a UI thing, not a PL
thing.  About 30 seconds ago, I typed `%clear` in IPython... I'm not
certain it is the first time I've ever done so, but quite likely.  It was
amazing, my screen was cleared :-).

On Tue, Oct 13, 2020 at 6:38 PM Guido van Rossum  wrote:

> Can one of the educators on the list explain why this is such a commonly
> required feature? I literally never feel the need to clear my screen -- but
> I've seen this requested quite a few times in various forms, often as a bug
> report "IDLE does not support CLS". I presume that this is a common thing
> in other programming environments for beginners -- even C++ (given that it
> was mentioned). Maybe it's a thing that command-line users on Windows are
> told to do frequently? What am I missing that students want to do
> frequently? Is it a holdover from the DOS age?
>
> On Tue, Oct 13, 2020 at 11:25 AM Mike Miller 
> wrote:
>
>>
>> On 2020-10-13 06:19, Stestagg wrote:
>> > For example, the pypi `console` library provides a method:
>> `console.sc.reset()`
>> > that behaves similarly to `CLS` on windows and also appears to be
>> fairly
>> > reliable cross-platform.
>>
>>
>> Yes, there is more to it than appears at first glance.  There is
>> resetting the
>> terminal, clearing the currently visible screen, and/or the scrollback
>> buffer as
>> well.
>>
>> The legacy Windows console has another limitation in that I don't believe
>> it has
>> a single API call to clear the whole thing.  One must iterate over the
>> whole
>> buffer and write spaces to each cell, or some similar craziness.  That's
>> why
>> even folks writing C++ just punt and do a system("cls") instead.
>>
>> With the mentioned lib console, the example above prints the ANSI codes
>> to do a
>> terminal reset, and while that works widely these days, it should not be
>> the
>> first choice.  It would be better to use the cross-platform wrapper
>> functions in
>> the console.utils module, either:
>>
>>  # A DOS-like reset, clears screen and scrollback, also aliased to
>> cls()
>>  reset_terminal()
>>
>>  # A Unix-like clear, configurable via param, and aliased to clear()
>>  clear_screen()
>>
>> -Mike
>> ___
>> Python-ideas mailing list -- python-ideas@python.org
>> To unsubscribe send an email to python-ideas-le...@python.org
>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>> Message archived at
>> https://mail.python.org/archives/list/python-ideas@python.org/message/MX54AOXMYJHGRVOO2XW3J7JWHQDDUKPQ/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
>
> --
> --Guido van Rossum (python.org/~guido)
> *Pronouns: he/him **(why is my pronoun here?)*
> 
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/J65P6UELD4RSSCSMAFYF52WADURHX2HL/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/Q6NTJLEPOTULRKE6WKJGXG4W7NMST7VU/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-13 Thread Christopher Barker
I have never had one of my students as for this.

Note that clearing the screen (command window these days) IS common -- at
least I do ti a lot :-) -- but with a keystroke, not in code.

I suspect Chris A is right -- this would be called for in a command-line /
menu driven app that wasn't using full blown curses.

I DID have a newbie (to Python, not programming) ask me a couple years ago
how to write a simple text terminal app --- in that case a game, where they
wanted to fully manipulate the screen, old fashioned DOS style. Honestly, I
had no idea, but pointed them to curses, which they found too complicated
-- but I don't think a clear terminal function would have solved their
problem anyway :-)

In short -- I see no need to add this to the stdlib.

-CHB



On Tue, Oct 13, 2020 at 3:47 PM Chris Angelico  wrote:

> On Wed, Oct 14, 2020 at 9:38 AM Guido van Rossum  wrote:
> >
> > Can one of the educators on the list explain why this is such a commonly
> required feature? I literally never feel the need to clear my screen -- but
> I've seen this requested quite a few times in various forms, often as a bug
> report "IDLE does not support CLS". I presume that this is a common thing
> in other programming environments for beginners -- even C++ (given that it
> was mentioned). Maybe it's a thing that command-line users on Windows are
> told to do frequently? What am I missing that students want to do
> frequently? Is it a holdover from the DOS age?
> >
>
> Quite honestly, I don't know. As an educator, I often see students
> clear the screen, and it's usually NOT helpful to me, as it erases
> potentially-valuable information about what happened. My best guess is
> that students get overwhelmed by the sheer quantity of information
> (XKCD 1369) and feel more comfortable erasing it.
>
> Another possibility is that someone's trying to create a hybrid of
> scrolling text UI and curses-like UI.
>
> Either way, I don't see this as something worth encouraging. IMO it's
> an attractive nuisance that ultimately won't help in very many
> situations. If you're in one of those few situations where it IS
> appropriate to clear the screen (and it's not better to grab ncurses),
> shelling out to clear/cls is good enough that it doesn't need to be a
> dedicated built-in.
>
> If other educators have the opposite view, I would definitely like to
> hear from you - would help me better understand my students' actions.
>
> ChrisA
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/VR5OFYAG3S4AFKLBXV5BOZBDMXELKYAO/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/O5H3BQVNHS5WTRJ3VA6BRL74OB377L3S/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-13 Thread Chris Angelico
On Wed, Oct 14, 2020 at 9:38 AM Guido van Rossum  wrote:
>
> Can one of the educators on the list explain why this is such a commonly 
> required feature? I literally never feel the need to clear my screen -- but 
> I've seen this requested quite a few times in various forms, often as a bug 
> report "IDLE does not support CLS". I presume that this is a common thing in 
> other programming environments for beginners -- even C++ (given that it was 
> mentioned). Maybe it's a thing that command-line users on Windows are told to 
> do frequently? What am I missing that students want to do frequently? Is it a 
> holdover from the DOS age?
>

Quite honestly, I don't know. As an educator, I often see students
clear the screen, and it's usually NOT helpful to me, as it erases
potentially-valuable information about what happened. My best guess is
that students get overwhelmed by the sheer quantity of information
(XKCD 1369) and feel more comfortable erasing it.

Another possibility is that someone's trying to create a hybrid of
scrolling text UI and curses-like UI.

Either way, I don't see this as something worth encouraging. IMO it's
an attractive nuisance that ultimately won't help in very many
situations. If you're in one of those few situations where it IS
appropriate to clear the screen (and it's not better to grab ncurses),
shelling out to clear/cls is good enough that it doesn't need to be a
dedicated built-in.

If other educators have the opposite view, I would definitely like to
hear from you - would help me better understand my students' actions.

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VR5OFYAG3S4AFKLBXV5BOZBDMXELKYAO/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-13 Thread Guido van Rossum
Can one of the educators on the list explain why this is such a commonly
required feature? I literally never feel the need to clear my screen -- but
I've seen this requested quite a few times in various forms, often as a bug
report "IDLE does not support CLS". I presume that this is a common thing
in other programming environments for beginners -- even C++ (given that it
was mentioned). Maybe it's a thing that command-line users on Windows are
told to do frequently? What am I missing that students want to do
frequently? Is it a holdover from the DOS age?

On Tue, Oct 13, 2020 at 11:25 AM Mike Miller 
wrote:

>
> On 2020-10-13 06:19, Stestagg wrote:
> > For example, the pypi `console` library provides a method:
> `console.sc.reset()`
> > that behaves similarly to `CLS` on windows and also appears to be fairly
> > reliable cross-platform.
>
>
> Yes, there is more to it than appears at first glance.  There is resetting
> the
> terminal, clearing the currently visible screen, and/or the scrollback
> buffer as
> well.
>
> The legacy Windows console has another limitation in that I don't believe
> it has
> a single API call to clear the whole thing.  One must iterate over the
> whole
> buffer and write spaces to each cell, or some similar craziness.  That's
> why
> even folks writing C++ just punt and do a system("cls") instead.
>
> With the mentioned lib console, the example above prints the ANSI codes to
> do a
> terminal reset, and while that works widely these days, it should not be
> the
> first choice.  It would be better to use the cross-platform wrapper
> functions in
> the console.utils module, either:
>
>  # A DOS-like reset, clears screen and scrollback, also aliased to
> cls()
>  reset_terminal()
>
>  # A Unix-like clear, configurable via param, and aliased to clear()
>  clear_screen()
>
> -Mike
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/MX54AOXMYJHGRVOO2XW3J7JWHQDDUKPQ/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/J65P6UELD4RSSCSMAFYF52WADURHX2HL/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-13 Thread Mike Miller



On 2020-10-13 06:19, Stestagg wrote:
For example, the pypi `console` library provides a method: `console.sc.reset()` 
that behaves similarly to `CLS` on windows and also appears to be fairly 
reliable cross-platform.



Yes, there is more to it than appears at first glance.  There is resetting the 
terminal, clearing the currently visible screen, and/or the scrollback buffer as 
well.


The legacy Windows console has another limitation in that I don't believe it has 
a single API call to clear the whole thing.  One must iterate over the whole 
buffer and write spaces to each cell, or some similar craziness.  That's why 
even folks writing C++ just punt and do a system("cls") instead.


With the mentioned lib console, the example above prints the ANSI codes to do a 
terminal reset, and while that works widely these days, it should not be the 
first choice.  It would be better to use the cross-platform wrapper functions in 
the console.utils module, either:


# A DOS-like reset, clears screen and scrollback, also aliased to cls()
reset_terminal()

# A Unix-like clear, configurable via param, and aliased to clear()
clear_screen()

-Mike
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MX54AOXMYJHGRVOO2XW3J7JWHQDDUKPQ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-13 Thread Stestagg
It's not uncommon for C++ tutorials etc, to refer to using:

system("cls");

to clear the screen (in windows console environments only).  I assume this
is what ankith was talking about.

The python equivalent would be:

import os
os.system('cls')

or in the repl:

_ = os.system('cls').

Note, ipython (on linux only, it seems) adds a built-in alias called
`clear` which does the same thing.

Unfortunately, implementing this behaviour in a reliable, cross-platform
way is reasonably hard.  Python has the standard library module: curses,
which can be made to provide similar behaviour (with some side-effects) but
this doesn't work in the traditional windows console.  There may be some
other functionality buried somewhere in the stdlib that does this?

Some third party libraries do a reasonable job at providing this feature,
and it feels like 3rd party libraries are the correct place for this

For example, the pypi `console` library provides a method:
`console.sc.reset()` that behaves similarly to `CLS` on windows and also
appears to be fairly reliable cross-platform.

Steve

On Tue, Oct 13, 2020 at 1:41 PM Serhiy Storchaka 
wrote:

> 13.10.20 09:07, ankith abhayan пише:
> > I would like to request a new feature that allows you to clear the
> > console screen.
> > Like in c++, the CLS function
>
> There is no the CLS function in C++.
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/L3FA6UD2PAFKHVLYKQ7KYPSKMVWJJNFK/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7MYIBYPZ5DRAWTQIPN3LB22UWMUNJXTX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: New feature

2020-10-13 Thread Serhiy Storchaka
13.10.20 09:07, ankith abhayan пише:
> I would like to request a new feature that allows you to clear the
> console screen.
> Like in c++, the CLS function

There is no the CLS function in C++.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/L3FA6UD2PAFKHVLYKQ7KYPSKMVWJJNFK/
Code of Conduct: http://python.org/psf/codeofconduct/