Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged

Conversation

verygoodlee
Copy link
Contributor

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 natural-harmonia-gropius merged commit f833fff into natural-harmonia-gropius:master May 24, 2024
@natural-harmonia-gropius
Copy link
Owner

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

@verygoodlee
Copy link
Contributor Author

verygoodlee commented May 24, 2024

考虑过,但还是觉得空格更自由一点,单条命令也可随意换行,
最终选择空格是因为这个脚本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
Copy link
Owner

natural-harmonia-gropius commented May 25, 2024

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

[
  {
    "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
Copy link
Contributor Author

verygoodlee commented May 25, 2024

同意,这样很整齐

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants