Share your repls and programming experiences

← Back to all posts
Chess
LandanThompson

Chess is the best game ever invented blah blah blah

Voters
r0773n
pr0p3rno0b10
bitnetwork
LordPancake
RickyL7
ash15khng
OlofPettersson
PercyCho
LandanThompson
Comments
hotnewtop
ZachRedfern

it stops working when in check

ash15khng

How did you make the clickable terminal??

Pierce_Foley

@ash15khng also wondering please reply to me with answer too

bitnetwork

@ash15khng @Pierce_Foley
Almost everything that's possible with terminal escape codes is on this manual page, so do check it out: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking

All you really need to do is send "\x1b[?1000h\x1b[?1006h" to the terminal to enable mouse mode and then the terminal will send something along the lines of this to sys.stdin: "\x1b<0;x;y;m", where x & y are numbers as a string that represent the x and y positions of the click. You can use a regex or the parse module: https://pypi.org/project/parse/. Cheers!

ash15khng

@bitnetwork Sounds cool but complicated. I'll try to figure it out. Thanks anyways!
EDIT: what do you mean by send that string to the terminal?

bitnetwork

@ash15khng You can "send the string" via writing to sys.stdout or using a helper function like print. Basically how you would process user input except the user is the terminal in this case. This happens because the terminal is actually a middle man between your program and the user, and it parses what is sent over for special escape codes. They're called escape codes cause they start with the escape character: "\x1b"

The man page I linked is a lot more technical so maybe check out this wikipedia page first: https://en.wikipedia.org/wiki/ANSI_escape_code.
There's some pretty cool shit you can do (background/foreground colors, bold/italic/underline, hyperlinks, clearing the screen or the line, moving the cursor around, getting mouse events [move, click, drag], processing special user keys [like home, end, backspace, ctrl-a, alt-a, etc.]). Also note that windows is quite funky and doesn't use some of these advanced features like linux does (current windows 10 does tho for the most part). If you've ever used a linux terminal gui program like htop, nano, emacs, or vim, they use this same stuff.

ash15khng

@bitnetwork Wow that's cool!

r0773n

╰(°▽°)╯

r0773n

theres no castling :/

pythoncoder347

cool!

HackermonDev

@Castijos Which person did he copy it from?

mat1

@PDanielY He used some of my code, which I'm completely fine with since they gave credit :)

HackermonDev
SCOTBUTZBACH

I tried to run it, it said there is no module named "colors"

Warhawk947

It says 404