mirror of
https://github.com/nadrad/h-m-m.git
synced 2024-06-01 02:42:11 +02:00
added internal, file, and command clipboard types
* `--clipboard=os` uses xclip and similar applications (default). * `--clipboard=internal` uses an internal variable as the clipboard without exchanging content with external applications. * `--clipboard=file` along with `--clipboard-file=/path/filename` uses the file as the clipboard. * `--clipboard=command` uses `--clipboard-in-command="command %text%"` to send content and `--clipboard-out-command=command` to receive.
This commit is contained in:
parent
b655e0e928
commit
a61e4acfc7
75
h-m-m
75
h-m-m
|
@ -36,7 +36,7 @@ for ( $i = 1 ; $i < $alen ; $i++ )
|
||||||
if (substr($argv[$i],0,2) == '--')
|
if (substr($argv[$i],0,2) == '--')
|
||||||
{
|
{
|
||||||
$a = explode('=', substr($argv[$i],2));
|
$a = explode('=', substr($argv[$i],2));
|
||||||
$mm['arguments'][ str_replace('-','_',$a[0]) ] = ( $a[1] ?? true );
|
$mm['arguments'][ str_replace('-','_',$a[0]) ] = trim( $a[1] ?? true, '"' );
|
||||||
}
|
}
|
||||||
elseif (isset($mm['arguments']['filename']))
|
elseif (isset($mm['arguments']['filename']))
|
||||||
{
|
{
|
||||||
|
@ -106,6 +106,13 @@ config($mm, 'active_node_color', "\033[38;5;0m\033[48;5;172m\033[1m");
|
||||||
config($mm, 'message_color', "\033[38;5;0m\033[48;5;141m\033[1m");
|
config($mm, 'message_color', "\033[38;5;0m\033[48;5;141m\033[1m");
|
||||||
config($mm, 'doubt_color', "\033[38;5;168m");
|
config($mm, 'doubt_color', "\033[38;5;168m");
|
||||||
|
|
||||||
|
config($mm, 'clipboard', "os");
|
||||||
|
config($mm, 'clipboard_file', "/tmp/h-m-m");
|
||||||
|
config($mm, 'clipboard_in_command', "");
|
||||||
|
config($mm, 'clipboard_out_command', "");
|
||||||
|
|
||||||
|
$clipboard = '';
|
||||||
|
|
||||||
|
|
||||||
$mm['changes'] = [];
|
$mm['changes'] = [];
|
||||||
$mm['change_active_node'] = [];
|
$mm['change_active_node'] = [];
|
||||||
|
@ -199,17 +206,24 @@ function check_required_extensions()
|
||||||
|
|
||||||
function check_the_available_clipboard_tool(&$mm)
|
function check_the_available_clipboard_tool(&$mm)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if ($mm['clipboard'] == 'file' && !file_exists($mm['clipboard_file']))
|
||||||
|
file_put_contents($mm['clipboard_file'],'');
|
||||||
|
|
||||||
|
if ($mm['clipboard'] != 'os')
|
||||||
|
return;
|
||||||
|
|
||||||
if (PHP_OS_FAMILY === "Windows")
|
if (PHP_OS_FAMILY === "Windows")
|
||||||
{
|
{
|
||||||
$mm['clipboard']['write'] = "clip";
|
$mm['os_clipboard']['write'] = "clip";
|
||||||
$mm['clipboard']['read'] = 'powershell -sta "add-type -as System.Windows.Forms; [windows.forms.clipboard]::GetText()"';
|
$mm['os_clipboard']['read'] = 'powershell -sta "add-type -as System.Windows.Forms; [windows.forms.clipboard]::GetText()"';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PHP_OS_FAMILY === "Darwin")
|
if (PHP_OS_FAMILY === "Darwin")
|
||||||
{
|
{
|
||||||
$mm['clipboard']['write'] = "pbcopy";
|
$mm['os_clipboard']['write'] = "pbcopy";
|
||||||
$mm['clipboard']['read'] = 'pbpaste';
|
$mm['os_clipboard']['read'] = 'pbpaste';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,18 +242,18 @@ function check_the_available_clipboard_tool(&$mm)
|
||||||
switch ($tool)
|
switch ($tool)
|
||||||
{
|
{
|
||||||
case 'xclip':
|
case 'xclip':
|
||||||
$mm['clipboard']['write'] = 'xclip -selection clipboard';
|
$mm['os_clipboard']['write'] = 'xclip -selection clipboard';
|
||||||
$mm['clipboard']['read'] = 'xclip -out -selection clipboard';
|
$mm['os_clipboard']['read'] = 'xclip -out -selection clipboard';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'xsel':
|
case 'xsel':
|
||||||
$mm['clipboard']['write'] = 'xsel --clipboard';
|
$mm['os_clipboard']['write'] = 'xsel --clipboard';
|
||||||
$mm['clipboard']['read'] = 'xsel --clipboard';
|
$mm['os_clipboard']['read'] = 'xsel --clipboard';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'wl-copy':
|
case 'wl-copy':
|
||||||
$mm['clipboard']['write'] = 'wl-copy';
|
$mm['os_clipboard']['write'] = 'wl-copy';
|
||||||
$mm['clipboard']['read'] = 'wl-paste';
|
$mm['os_clipboard']['read'] = 'wl-paste';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1217,7 +1231,7 @@ function magic_readline(&$mm, $title)
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
elseif ($in=="\033\133\63\176")
|
elseif ($in=="\033\133\063\176")
|
||||||
{
|
{
|
||||||
$title =
|
$title =
|
||||||
mb_substr
|
mb_substr
|
||||||
|
@ -2107,22 +2121,47 @@ function paste_sub_tree(&$mm, $as_sibling )
|
||||||
|
|
||||||
function copy_to_clipboard(&$mm, $text)
|
function copy_to_clipboard(&$mm, $text)
|
||||||
{
|
{
|
||||||
$clip = popen($mm['clipboard']['write'],'wb');
|
switch ($mm['clipboard'])
|
||||||
if (!isset($clip)) return;
|
{
|
||||||
|
case 'os':
|
||||||
fwrite($clip,$text);
|
$clip = popen($mm['os_clipboard']['write'],'wb');
|
||||||
pclose($clip);
|
if (!isset($clip)) return;
|
||||||
|
fwrite($clip,$text);
|
||||||
|
pclose($clip);
|
||||||
|
break;
|
||||||
|
case 'internal':
|
||||||
|
$GLOBALS['clipboard'] = $text;
|
||||||
|
break;
|
||||||
|
case 'file':
|
||||||
|
file_put_contents($mm['clipboard_file'],$text);
|
||||||
|
break;
|
||||||
|
case 'command':
|
||||||
|
shell_exec(str_replace('%text%', '"'.$text.'"', $mm['clipboard_in_command']));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_from_clipboard(&$mm)
|
function get_from_clipboard(&$mm)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$text = 'clipboard unavailable!';
|
||||||
|
|
||||||
|
switch ($mm['clipboard'])
|
||||||
|
{
|
||||||
|
case 'os': $text = shell_exec($mm['os_clipboard']['read']); break;
|
||||||
|
case 'internal': $text = $GLOBALS['clipboard']; break;
|
||||||
|
case 'file': $text = file_get_contents($mm['clipboard_file']); break;
|
||||||
|
case 'command': $text = shell_exec($mm['clipboard_out_command']); break;
|
||||||
|
default: $text = "The clipboard type you've set is invalid!";
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
mb_ereg_replace
|
mb_ereg_replace
|
||||||
(
|
(
|
||||||
"[\000-\010\013-\037\177]|".BOM
|
"[\000-\010\013-\037\177]|".BOM
|
||||||
,''
|
,''
|
||||||
,shell_exec($mm['clipboard']['read'])
|
,$text
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
14
readme.md
14
readme.md
|
@ -101,6 +101,10 @@ The following are the settings in h-m-m:
|
||||||
max_undo_steps = 24
|
max_undo_steps = 24
|
||||||
active_node_color = "\033[38;5;0m\033[48;5;172m\033[1m"
|
active_node_color = "\033[38;5;0m\033[48;5;172m\033[1m"
|
||||||
message_color = "\033[38;5;0m\033[48;5;141m\033[1m"
|
message_color = "\033[38;5;0m\033[48;5;141m\033[1m"
|
||||||
|
clipboard = os
|
||||||
|
clipboard_file = /tmp/h-m-m
|
||||||
|
clipboard_in_command = ""
|
||||||
|
clipboard_out_command = ""
|
||||||
|
|
||||||
The colors are ASCII escape codes.
|
The colors are ASCII escape codes.
|
||||||
|
|
||||||
|
@ -118,6 +122,16 @@ Both underscores and dashes are accepted for the setting keys.
|
||||||
When multiple values exists, the highest priority goes to the command line arguments and the lowest to the config file.
|
When multiple values exists, the highest priority goes to the command line arguments and the lowest to the config file.
|
||||||
|
|
||||||
|
|
||||||
|
# Clipboard
|
||||||
|
|
||||||
|
The normal `os` clipboard works fine for most users, but some users may need other options:
|
||||||
|
|
||||||
|
* `os` uses the global clipboard via xclip and similar tools.
|
||||||
|
* `internal` uses an internal variable as the clipboard (won't exchange text with external applications).
|
||||||
|
* `file` uses `/tmp/h-m-m` by default, or aother file set by the `clipboard_file=/path/filename` setting as the clipboard.
|
||||||
|
* `command` uses `clipboard_in_command="command %text%"` to send content to a shell command and `clipboard_out_command="command"` to read content.
|
||||||
|
|
||||||
|
|
||||||
# Data format
|
# Data format
|
||||||
|
|
||||||
Mind maps are stored in plain text files (with `hmm` file extension by default) without metadata. The tree structure is represented by tab indentations; e.g.,
|
Mind maps are stored in plain text files (with `hmm` file extension by default) without metadata. The tree structure is represented by tab indentations; e.g.,
|
||||||
|
|
Loading…
Reference in a new issue