Scripting news

https://github.com/MiSTer-devel/Main_MiSTer/wiki

Moderators: Mug UK, Zorro 2, Greenious, spiny, Sorgelig, Moderator Team

Locutus73
Captain Atari
Captain Atari
Posts: 493
Joined: Wed Feb 07, 2018 6:13 pm

Re: Scripting news

Postby Locutus73 » Mon May 27, 2019 3:53 pm

Sorgelig wrote:i will implement key injection


In the meantime I did some researches, probably it's all trivial stuff for you, but I'll share the same (worst case I lost some time).
I managed to run a script in a second agetty terminal temporarily stopping the main one with:

Code: Select all

kill -n 19 $(ps -A | grep "[a]getty --nohostname -L tty0 xterm$" | grep -oE "^[0-9]+") && /sbin/agetty  --autologin root --login-program /media/fat/Scripts/ini_settings.sh --nohostname -L tty0 xterm && kill -n 18 $(ps -A | grep "[a]getty --nohostname -L tty0 xterm$" | grep -oE "^[0-9]+")

It seems to work quite well: when the script exits, the main agetty takes control again.
[EDIT]--skip-login instead of --autologin root works the same[/EDIT]
For input injecting you can grab some code here if you like it https://github.com/Locutus73/uinput-injector
It's pretty basic and simple...

What do you think about a scripts_gui_old=0 ini option for people needing to use a low res video analog output?

Thank you in advance.
Best regards.

Locutus73

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Mon May 27, 2019 4:25 pm

Why not just run getty on tty1 without killing tty0?

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Mon May 27, 2019 5:15 pm

latest linux release includes Weston GUI as part of my experiment.
Weston is lightweight GUI on framebuffer.
Not sure if we need it. If it's useless then i will remove it in the next Linux release.

to start it:

Code: Select all

export XDG_RUNTIME_DIR=/tmp
weston --tty=2

There are no apps in desktop except the terminal. I don't know if it's supposed to be so empty in default config or it's just config is wrong.

Locutus73
Captain Atari
Captain Atari
Posts: 493
Joined: Wed Feb 07, 2018 6:13 pm

Re: Scripting news

Postby Locutus73 » Mon May 27, 2019 5:40 pm

Sorgelig wrote:Why not just run getty on tty1 without killing tty0?

If I run agetty on tty1 or tty0 or whatever, the main agetty (the inittab one) still contends the framebuffer or something with the new one and after some keyboard inputs it takes control... actually sometimes you see the new one and sometimes the original inittab agetty... a mess. Maybe I'm doing something stupid, I don't know.
The kill -n 19 doesn't actually kill the original agetty (which would be respawned immediately by init), but it sends a SIGSTOP which pauses it, so the new one is free to work, until the script exits and a SIGCONT is sent to the original agetty that wakes up.
It seems to work, I almost finished some main MiSTer code (including a SCRIPTS_OLD_GUI setting) I'll send to you through a PR. I'm just fighting with something in the GUI I don't understand right now...

Thank you.
Regards.

Locutus73

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Mon May 27, 2019 6:28 pm

It's not a problem to start several gettys on different tty.
But now the problem is how to check the script execution.
With simple system() function i get back control after script finished, it works good. But in this case it's impossible to inject the keys from gamepad to keyboard as MiSTer process is stalled.
Need more complex control..

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Mon May 27, 2019 6:29 pm

by the way, font ini setting is still broken.

Locutus73
Captain Atari
Captain Atari
Posts: 493
Joined: Wed Feb 07, 2018 6:13 pm

Re: Scripting news

Postby Locutus73 » Mon May 27, 2019 7:03 pm

Sorgelig wrote:It's not a problem to start several gettys on different tty.

I didn't manage to have a stable situation launching new agetty with a script as --login-program

Sorgelig wrote:But now the problem is how to check the script execution.
With simple system() function i get back control after script finished, it works good. But in this case it's impossible to inject the keys from gamepad to keyboard as MiSTer process is stalled.
Need more complex control..

I made a PR with my half finished attempt.
I used the popen approach, so, maybe it can be useful for injecting keys, I don't know, I'm not sure... maybe it can be useful, you can take a look if you like it.
I have a problem when the script exits and I re-enable the GUI, it acts weirdly, just like a keyboard button is stuck or something, probably it's something super easy for you.

Sorgelig wrote:by the way, font ini setting is still broken.

What doesn't work for you? I fixed a thing today... but the font settings (for now) requires a /media/fat/font directory populated with fonts.

Regards.

Locutus73

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Mon May 27, 2019 8:01 pm

You run in front of train :)
Let me finish what i'm doing before making PR.
That was just my thought while i'm working on it. It's already fine in my code. Just need to polish the code.

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Mon May 27, 2019 10:10 pm

Locutus73 wrote:What doesn't work for you? I fixed a thing today... but the font settings (for now) requires a /media/fat/font directory populated with fonts.

after choosing the font from list i get an empty string in font option.

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Mon May 27, 2019 10:25 pm

By the way, the main path for MiSTer.ini is /media/fat/MiSTer.ini It supersedes the one from config dir if found.
Config dir is mostly for configs not suitable for manual editing.
You can add patch check. if /media/fat/MiSTer.ini is found then use it, otherwise use deprecated path /media/fat/config/MiSTer.ini

Locutus73
Captain Atari
Captain Atari
Posts: 493
Joined: Wed Feb 07, 2018 6:13 pm

Re: Scripting news

Postby Locutus73 » Tue May 28, 2019 10:50 am

Sorgelig wrote:You run in front of train :)
Let me finish what i'm doing before making PR.
That was just my thought while i'm working on it. It's already fine in my code. Just need to polish the code.

:cheers:

Sorgelig wrote:
Locutus73 wrote:What doesn't work for you? I fixed a thing today... but the font settings (for now) requires a /media/fat/font directory populated with fonts.

after choosing the font from list i get an empty string in font option.

Mmmhh... I'm not able to replicate the issue, but testing that I found a different bug in the font settings.
Can you test the very latest script please?

Sorgelig wrote:By the way, the main path for MiSTer.ini is /media/fat/MiSTer.ini It supersedes the one from config dir if found.
Config dir is mostly for configs not suitable for manual editing.
You can add patch check. if /media/fat/MiSTer.ini is found then use it, otherwise use deprecated path /media/fat/config/MiSTer.ini

Done.
Another change I made is: previously I used /media/fat/config/dialogrc for customizing dialg behaviour (and hiding the background black stipe bug); now I check if ~/.dialogrc exists and create a .dialogrc in the same dir as the script only when needed.
So if you decide to use dialog (I'm thinking to btpair script) and make a ~/.dialogrc file with the colors you like, that will be the global look of all scripts.

Regards.

Locutus73

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Tue May 28, 2019 11:04 am

~/ is read-only unless you remount the / as rw.
Scripts (even in FB) don't remount / as rw, so it's highly advised not to do it without real need.
It's fine to place dialogrc in the same folder as script. this would be the best place.

Locutus73
Captain Atari
Captain Atari
Posts: 493
Joined: Wed Feb 07, 2018 6:13 pm

Re: Scripting news

Postby Locutus73 » Tue May 28, 2019 11:26 am

Sorgelig wrote:~/ is read-only unless you remount the / as rw.
Scripts (even in FB) don't remount / as rw, so it's highly advised not to do it without real need.
It's fine to place dialogrc in the same folder as script. this would be the best place.


Yes I know the root filesystem is RO and I remount it RW and RO in some scripts when needed, i.e. for making mount_cifs.sh auto executed at boot (if the user willingly enables an option in its ini); but this isn't the case, there was a misunderstanding.
What I meant is that I first check if ~/.dialogrc exists and if it exists I use that (no writing, just reading).
If it doesn't exist then I create and customize .dialogrc in the same directory as the script.
So if you decide to use dialog in the future (i.e. for btpair) and decide to customize its appearance making a custom ~/.dialogrc in a future Linux update, then my scripts will automatically use that, having a consistent look with yours.

Regards.

Locutus73

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Tue May 28, 2019 12:13 pm

Locutus73 wrote:
Sorgelig wrote:~/ is read-only unless you remount the / as rw.
Scripts (even in FB) don't remount / as rw, so it's highly advised not to do it without real need.
It's fine to place dialogrc in the same folder as script. this would be the best place.


Yes I know the root filesystem is RO and I remount it RW and RO in some scripts when needed, i.e. for making mount_cifs.sh auto executed at boot (if the user willingly enables an option in its ini); but this isn't the case, there was a misunderstanding.
What I meant is that I first check if ~/.dialogrc exists and if it exists I use that (no writing, just reading).
If it doesn't exist then I create and customize .dialogrc in the same directory as the script.
So if you decide to use dialog in the future (i.e. for btpair) and decide to customize its appearance making a custom ~/.dialogrc in a future Linux update, then my scripts will automatically use that, having a consistent look with yours.

Regards.

Locutus73


oh, i see.
But font setting still doesn't work. It gives me empty string.

By the way, may be it's worth to remove ok/cancel from advanced editing. Anyway you go back to main dialog where you need to confirm the write to file. So i think intermediate ok/cancel is redundant.

P.S.: i've used the name for font dir - Font. Though it could be a problem. Renamed to font - it didn't fix the problem. Still empty string.

Locutus73
Captain Atari
Captain Atari
Posts: 493
Joined: Wed Feb 07, 2018 6:13 pm

Re: Scripting news

Postby Locutus73 » Tue May 28, 2019 12:20 pm

Sorgelig wrote:But font setting still doesn't work. It gives me empty string.

Can you share here (or just PM me) your MiSTer.ini? And the output of ls -la /media/fat/font ?
Does that happen with every font you choose or just with some specific ones?

Sorgelig wrote:By the way, may be it's worth to remove ok/cancel from advanced editing. Anyway you go back to main dialog where you need to confirm the write to file. So i think intermediate ok/cancel is redundant.

I don't know, the dialog editor isn't that great, maybe someone could make a mess and would prefer to cancel instead of exiting not saving and relaunching the script. In the end it doesn't clutter the GUI.

Regards.

Locutus73

Locutus73
Captain Atari
Captain Atari
Posts: 493
Joined: Wed Feb 07, 2018 6:13 pm

Re: Scripting news

Postby Locutus73 » Wed May 29, 2019 10:12 am

Sorgelig wrote:
Locutus73 wrote:So if you decide to use dialog in the future (i.e. for btpair) and decide to customize its appearance making a custom ~/.dialogrc in a future Linux update, then my scripts will automatically use that, having a consistent look with yours.

oh, i see.

Speaking about consistency of presentation, this is just a first (very little) step.
Kitrinx/Rysha suggested the use of Dear ImGui (https://github.com/ocornut/imgui), a very nice library for easily coding nice GUI in C++ (and other languages) which can work with SDL and framebuffer... and that made me think: what if we use that library in order to write a graphical dialog replacement 100% compatible with the standard dialog commandline arguments (starting with just the arguments we use)? We would mantain the flexibility of scripts with a nicer looking GUI consistent along MiSTer (i.e. btpair script). In the end this approach isn't new and in Linux we have many graphical tools for that (wich unhopefully require X and heavy dependacies, i.e. Zenity) more or less compatible with dialog wich is a widespread standard (i.e. the whole Debian textual installer is dialog based). Something like that would transcend MiSTer use, it could be useful on any Linux system.

Regards.

Locutus73

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Wed May 29, 2019 10:56 am

Locutus73 wrote:Speaking about consistency of presentation, this is just a first (very little) step.
Kitrinx/Rysha suggested the use of Dear ImGui (https://github.com/ocornut/imgui), a very nice library for easily coding nice GUI in C++ (and other languages) which can work with SDL and framebuffer... and that made me think: what if we use that library in order to write a graphical dialog replacement 100% compatible with the standard dialog commandline arguments (starting with just the arguments we use)? We would mantain the flexibility of scripts with a nicer looking GUI consistent along MiSTer (i.e. btpair script). In the end this approach isn't new and in Linux we have many graphical tools for that (wich unhopefully require X and heavy dependacies, i.e. Zenity) more or less compatible with dialog wich is a widespread standard (i.e. the whole Debian textual installer is dialog based). Something like that would transcend MiSTer use, it could be useful on any Linux system.

It's up to you.
Some additional apps like BT pair should be good, especially for those who have special conditions and trouble of pairing. Original simple BT pair will remain on OSD as is.

User avatar
kitrinx
Captain Atari
Captain Atari
Posts: 173
Joined: Wed Sep 26, 2018 6:03 am

Re: Scripting news

Postby kitrinx » Wed May 29, 2019 2:30 pm

A graphical dialog wrapper would probably be a good stop-gap. I think in the long run, scripts should only serve the role of very niche/special purpose actions. If something needs to be done by a user all the time (updating, ini settings) a dedicated graphical method is the only sensible choice.

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Wed May 29, 2019 2:55 pm

ini options originally supposed to be set once and forget.

Locutus73
Captain Atari
Captain Atari
Posts: 493
Joined: Wed Feb 07, 2018 6:13 pm

Re: Scripting news

Postby Locutus73 » Wed May 29, 2019 4:44 pm

kitrinx wrote:If something needs to be done by a user all the time (updating, ini settings) a dedicated graphical method is the only sensible choice.

I don't agree, at least not totally... let's say partially :D ... for some specific tasks, especially sporadic OS management tasks, like installing, updating, setting configs, backups, restores, spring-cleanings, etc. scripting is a natural and flexible tool, especially in an army-knife OS as Linux where they are traditionally used everywhere for this: it's their traditional playfield. But I totally agree they aren't a tool for everything, i.e. a main frontend for cores and roms... but we discussed this extensively.

Anyway I find the imgui-dialog idea interesting not only for MiSTer, but in general (RPis would benefit :lol:) and I appreciate your recommendation as much I'll appreciate any help with this idea.

Thank you in advance.
Regards.

Locutus73

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Wed May 29, 2019 4:52 pm

There is one more idea:
Weston GUI i've added. It starts very quick and can be used for settings. Check if you can use it.
All libraries should be there already.

Locutus73
Captain Atari
Captain Atari
Posts: 493
Joined: Wed Feb 07, 2018 6:13 pm

Re: Scripting news

Postby Locutus73 » Wed May 29, 2019 4:59 pm

Sorgelig wrote:There is one more idea:
Weston GUI i've added. It starts very quick and can be used for settings. Check if you can use it.
All libraries should be there already.

I started to take a look at it some days ago... I'll check it again for sure in the future.
Please don't remove it in the near future, things need some time to mature... I mean, few days ago we had no framebuffer at all...

Regards.

Locutus73

User avatar
kitrinx
Captain Atari
Captain Atari
Posts: 173
Joined: Wed Sep 26, 2018 6:03 am

Re: Scripting news

Postby kitrinx » Wed May 29, 2019 6:33 pm

Sorgelig wrote:ini options originally supposed to be set once and forget.


In practice, I add custom groups and settings all the time for different cores, like vsync_adjust settings, vscale, etc. Maybe I am a bit of an advanced user, but even a new user would have a much easier time if such settings were more obviously accessible. I once brought my mister to a hotel and had a hard time because I didn't have a way to disable vsync adjust there. No card reader, network, or keyboard, and the TV didn't like the setting. I spent the whole time playing gameboy games because I had vsync_adjust set to 0 for that core.

MartinW
Atari User
Atari User
Posts: 34
Joined: Thu May 09, 2019 9:28 pm

Re: Scripting news

Postby MartinW » Wed May 29, 2019 8:23 pm

kitrinx wrote:In practice, I add custom groups and settings all the time for different cores, like vsync_adjust settings, vscale, etc.


Ditto.

I'm certainly not advanced when it comes to MiSTer but I guess as a developer and sysadmin I maybe more advanced generally than some. I basically have general pretty lax settings in the main section where I don't really care too much, so generally I use vga_scaler=1, vsync_adjust=0 (etc.) and then on something like Minimig where I very much do care then I will override at the bottom with vga_scaler=0 in a core section.

That said, I don't expect to be doing this all the time. Once I'm happy I hope to only have to go into the INI file manually if I start to explore another core, or maybe some new features are added to one of the cores that I am interested in?

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5248
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Scripting news

Postby Sorgelig » Wed May 29, 2019 8:47 pm

trying to add mouse support in terminal.
added gpm package - now mouse works but completely ignores the application. It always selects the part of screen by cursor regardless if it's menu or not. So both MC and Dialog apps don't react on mouse clicks.
Cannot find solution for this problem.
Anyone?


Return to “MiSTer”

Who is online

Users browsing this forum: No registered users and 16 guests