1

This is my first post so please tell me if there is anything I do wrongly or can change to improve upon my posts ;).

So I'm a programmer beginner, mainly doing school projects. Lately I've been exploring python on my own for a bit. I made a program that can automatically test if coupon codes for a certain site are valid coupons (I know this is a questionable thing to do, and did it for sheer curiosity). Anyway my program prints for every coupon code whether it is valid, and print the valid coupons to a different text file.

As my program prints out for every code if it is valid I get a lot of lines in the terminal as output. The valid codes are coloured green using ANSI sequences.

My question is if it is possible to keep all the valid codes on top of the terminal, while it is still searching for new codes? It would be really nice if only one line remained that shows what the program is doing, while it clears all the invalid printed coupon codes and keeps all the printed lines for the valid ones.

Anyway I'm not sure if this is possible at all, but I'm quite curious.

Looking forward to any answers, and I'd like to thank everyone in advance!

  • 1
    Hi, @Moonreaderx welcome to Stack Overflow! It would be really helpful if you could share some code to show us what you've done so far and how it can be improved. Some additional guidelines for asking a good question can be found [here](https://stackoverflow.com/help/how-to-ask) – etemple1 May 09 '17 at 20:08
  • Is this a Linux terminal you want to output to? – Vinícius Figueiredo May 09 '17 at 20:09
  • 1
    There are ansi codes for moving around the screen but it gets difficult juggling screen geometries. The curses module does it for you, but curses itself is a bit of a lift. This may be a good time to look into a GUI that will pop up windows. Python comes with `tkinter` which is a good start. – tdelaney May 09 '17 at 20:10
  • @etemple1 Thanks for your comment! Making the title last seems to be a good tip for me =P. – Moonreaderx May 10 '17 at 07:22
  • @tdelaney Thanks for your comment. Curses seems to be the way to go =D! If I won't get it to work, I might try to make a GUI with tkinter. – Moonreaderx May 10 '17 at 07:23

1 Answers1

0

Curses is a pre-built library(for Linux version) you might want to look into for splitting screens on the terminal. There's a Windows build of Curses available, you need to install it accordingly to your Python version, you can find the available .whl files here.

An example of an application using curses to something very similar to your idea can be seen in this answer.

Community
  • 1
  • 1
Vinícius Figueiredo
  • 6,300
  • 3
  • 25
  • 44
  • Hey, thanks for your answer, and the links are really helpful. This seems to be the solution. I'll try this out, and might try get a cross-platform solution after I get it working, or move on to @tdelaney his suggestion by making a GUI with tkinter. *I'd upvote your post but don't have enough reputation yet, sorry =( – Moonreaderx May 10 '17 at 07:25