• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Way to clear screen?

 
Greenhorn
Posts: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to clear the screen and move the cursor back to the top of the screen???

What I want is after I have don't something in my program is to ruturn to the main menu. However at the moment when I return to the main menu it jsut appears at the bottom of the screen with all the previous text above it..

A way to clear the screen would be cool

Thanks...
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Cramphorn:

A way to clear the screen would be cool



Cool, but not platform independent. Also, most applications use a windowed GUI in favor of a console interface. Given these two reasons, it's no surprise that Java has limited console capabilities. Check out this post for your options.
 
Ben Cramphorn
Greenhorn
Posts: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you and apologies for the late reply.
 
Ranch Hand
Posts: 91
3
Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ben Cramphorn wrote:Thank you and apologies for the late reply.



12 years!?

Now you're a man who's all about tying loose ends!
 
Marshal
Posts: 27372
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome back to the Ranch, Ben!
 
Saloon Keeper
Posts: 26047
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that isn't a record, I'd like to know what is!

A lot of devices will honor a "Control-L" character code. I believe that hex 0C. Its official ASCII name is "form feed", and on compliant text printers, it initiates a page eject operation. Which is the paper equivalent of clearing the screen and going to the top, so a lot of "glass TTY" monitors adopted CTL-L as a clear-screen convention as well. With the advent of window-based GUI systems, virtual terminals became popular and true to their name, they mimicked the behavior of their corresponding physical terminals.

Older terminal apps usually allowed you to configure to emulate specific popular physical terminals, such as the DEC VT-100 terminal. A quick look at my desktop seems to indicate that these days, the virtual terminals are more generic and abstract.

There are common escape sequences for positioning the text cursor, blanking, color and intensity and so forth. The Unix/Linux curses package was created to translate them to hardware-specific command sequences so that portable "text gui" apps could be written. That was useful back before servers commonly ran with windowing systems. And frankly, I'm not keen on the trend that servers should be required to be running high-resolution graphics/window systems anyway, I do most of my administration from a remote console so having all that overhead on the server is mostly just an annoyance that prevents me from recycling older monitors and video cards.

So, if you're brave, I recommend outputting a CTRL-L and buffer flush. It will work in an awful lot of cases, but not all of them. If full portability is essential, then you need to be working with a graphics manager and issuing graphics API commands.
 
Ben Cramphorn
Greenhorn
Posts: 19
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:If that isn't a record, I'd like to know what is!

A lot of devices will honor a "Control-L" character code. I believe that hex 0C. Its official ASCII name is "form feed", and on compliant text printers, it initiates a page eject operation. Which is the paper equivalent of clearing the screen and going to the top, so a lot of "glass TTY" monitors adopted CTL-L as a clear-screen convention as well. With the advent of window-based GUI systems, virtual terminals became popular and true to their name, they mimicked the behavior of their corresponding physical terminals.

Older terminal apps usually allowed you to configure to emulate specific popular physical terminals, such as the DEC VT-100 terminal. A quick look at my desktop seems to indicate that these days, the virtual terminals are more generic and abstract.

There are common escape sequences for positioning the text cursor, blanking, color and intensity and so forth. The Unix/Linux curses package was created to translate them to hardware-specific command sequences so that portable "text gui" apps could be written. That was useful back before servers commonly ran with windowing systems. And frankly, I'm not keen on the trend that servers should be required to be running high-resolution graphics/window systems anyway, I do most of my administration from a remote console so having all that overhead on the server is mostly just an annoyance that prevents me from recycling older monitors and video cards.

So, if you're brave, I recommend outputting a CTRL-L and buffer flush. It will work in an awful lot of cases, but not all of them. If full portability is essential, then you need to be working with a graphics manager and issuing graphics API commands.



Great post. Thanks for taking the time to write it. I'll give it a go and let you know how I get on.
 
Marshal
Posts: 5409
326
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome back, again, Ben. Only 5 years this time

This thread is a real slow burner....
 
Master Rancher
Posts: 278
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, usually I'm against "topic-/thread-'necromancing'", but in this it were just two really long delayed replies.

@OP
I'm not sure how important this topic still is to you as it was nearly two decades ago, but a lot has changed since back then.
For some time there was a java-binding for the nCurses lib (nCurses is the successor of curses lib - what was already mentioned back then) but the last time I checked the last update was several years ago. It's unlikely it still works. And If I remember correctly it was available as 32 bit only.
So, if you still require such feature maybe writing your own native lib could be a way to go. The requested feature is quite platform dependent so it was not implemented in Java. It also differs a lot what type of "terminal" you use: CMD or PowerShell on windows, one of the many shells on linux, going networked via telnet/ssh and a terminal-emulator like PuTTY or even serial to a real hardware terminal like a VT-100 or VT-220.

It sure can be done. The question is with how much effort for the designated target platform. If you have access to a graphical desktop creating a GUI might be a way to go. If not a common way today is ssh - I'm not sure if the protocol has some escape sequences to do it. Telnet could also be a way - but it's unencrypted.
 
Tim Holloway
Saloon Keeper
Posts: 26047
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't "thread-necromancing". It's pretty obvious that Ben is inbound from Alpha Centauri and there's just been a lot of message propagation delay. Speed of light - not just a good idea - it's The Law!!!

Seriously, though, the formfeed character has been honored on pretty much every terminal device that ever had hardware support for screen clearing or page ejection, so a "curses" API shouldn't be necessary. Curses was designed to provide device independence back when there were dozens of different brands and models of terminal devices.

If memory serves, curses was basically obsoleted in Unix/Linux by termcaps. Rather than invoke a library, you'd now just use control codes for a virtual terminal device, which is typically DEC VT-100 emulation (set as an environment option). Termcaps would then translate command codes as needed.
 
Get out of my mind! Look! A tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic