Skip to content
Sign upLog in
← Back to Community

Chess

Profile icon
LandanThompson

Chess is the best game ever invented blah blah blah

Voters
Profile icon
D4rkPl3b
Profile icon
polyhex
Profile icon
amyuwupoggers
Profile icon
ThePeople2000
Profile icon
ZaraarTahir
Profile icon
Edward06ewe2701
Profile icon
johnnf7788
Profile icon
r0773n
Profile icon
pr0p3rno0b10
Profile icon
bitnetwork
Comments
hotnewtop
Profile icon
ZachRedfern

it stops working when in check

Profile icon
r0773n

theres no castling :/

Profile icon
ash15khng

How did you make the clickable terminal??

Profile icon
Pierce_Foley

@ash15khng
also wondering please reply to me with answer too

Profile icon
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!

Profile icon
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?

Profile icon
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.

Profile icon
ash15khng

@bitnetwork
Wow that's cool!

Profile icon
r0773n

╰(°▽°)╯

Profile icon
pythoncoder347

cool!

Profile icon
HackermonDev

@Castijos
Which person did he copy it from?

Profile icon
HackermonDev

@mat1
ok

Profile icon
SCOTBUTZBACH

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

Profile icon
Navinor

It says 404