natural-harmonia-gropius / input-event

Enhanced input.conf for mpv-player. with better, conflict-free, low-latency event mechanism.
MIT License
51 stars 5 forks source link

Support for string array command syntax in JSON configuration file #45

Closed verygoodlee closed 6 months ago

verygoodlee commented 6 months ago

JSON配置中支持一种命令的新语法,不影响原有语法。

主要是有些命令太长了,例如script-message-tochange-list等,有时候还要连续几个命令写在一起,写成数组的形式就可以随意换行了。

[
  {
    "key": "F2",
    "on": {
      "click": ["change-list glsl-shaders clr '';", 
        "change-list glsl-shaders append",
        "'~~/shaders/Anime4K_Darken_HQ.glsl';",
        "change-list glsl-shaders append",
        "'~~/shaders/Anime4K_Thin_HQ.glsl';",
        "...", "..."
      ]
    }
  }
]
natural-harmonia-gropius commented 6 months ago

连接符固定为 "; " 会不会好一点,["change-list glsl-shaders append", "'~~/shaders/Anime4K_Darken_HQ.glsl';"] 有点怪

verygoodlee commented 6 months ago

考虑过,但还是觉得空格更自由一点,单条命令也可随意换行, 最终选择空格是因为这个脚本execute-lua-code可传入lua代码执行,

一些简单的需求用命令实现不了,写脚本的话只需要几行,就比较适合用它,如果可换行的话,可读性会强很多, 在这个例子里,即使单条命令也有换行的需求,只能选择用空格连接。

例如在Windows上打开配置文件夹

[
"script-message-to misc execute-lua-code",
"\"",
" local config_dir = mp.command_native({'expand-path', '~~/'}) ",
" config_dir = mp.command_native({'normalize-path', config_dir}) ",
" mp.commandv('run', 'explorer.exe', config_dir) ",
"\""
]
natural-harmonia-gropius commented 6 months ago

这样如何? 外层用;连接,内层空格连接

[
  {
    "key": "F2",
    "on": {
      "click": [
        "change-list glsl-shaders clr ''",
        "change-list glsl-shaders append '~~/shaders/Anime4K_Darken_HQ.glsl'",
        "change-list glsl-shaders append '~~/shaders/Anime4K_Thin_HQ.glsl'",
        [
          "script-message-to misc execute-lua-code",
          "\"",
          " local config_dir = mp.command_native({'expand-path', '~~/'})",
          " config_dir = mp.command_native({'normalize-path', config_dir})",
          " mp.commandv('run', 'explorer.exe', config_dir)",
          "\""
        ],
        "..."
      ]
    }
  }
]
verygoodlee commented 6 months ago

同意,这样很整齐