1

I am making a text based video game with python, and I need a way to change the cursor type from inside python. Here is my code:

from os import system,getenv
from json import loads,dumps
import uuid
apd = getenv("LOCALAPPDATA")
pf = loads(open(rf"{apd}\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json").read())
pf['profiles']['list'].append({"guid":str(uuid.uuid4()),'name':"Game","commandline": "C:\\Windows\\System32\\cmd.exe","cursorShape": "vintage","font": {"face": "Consolas"},})
open(rf"{apd}\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json",'w').write(dumps(pf))
system('wt -F -d {{PATH TO FILE}} -p "Game" --title Game python game.py')
greatusername
  • 129
  • 1
  • 10

1 Answers1

1

I'm not sure it's a great idea to place a dependency on Windows Terminal, but if you do go that route, the right way to do this is via the JSON fragment extension feature.

Don't risk modifying the user's Windows Terminal settings file directly via Python. Users will be quite (rightly) upset if you muck up their settings if something goes wrong.

JSON fragment extensions give you the ability to create a separate settings fragment that only applies to your application/profile.

For example, create a fragment:

{
  "profiles": [
    {
      "name": "My Game",
      "commandline": "python.exe /path/to/game.py",
      "cursorShape": "vintage",
      "font": {"face": "Consolas"}
    }
  ]
}

Place this file in either:

  • C:\ProgramData\Microsoft\Windows Terminal\Fragments\{app-name}\{file-name}.json: For all users on the system
  • C:\Users\<user>\AppData\Local\Microsoft\Windows Terminal\Fragments\{app-name}\{file-name}.json: For only the current user
NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70