mirror of
https://github.com/nadrad/h-m-m.git
synced 2024-06-01 02:42:11 +02:00
replaced 'readline' with 'magic_readline'!
This commit is contained in:
parent
890e6cb45f
commit
4bccfadb76
135
h-m-m
135
h-m-m
|
@ -1108,44 +1108,10 @@ function insert_node(&$mm, $type)
|
||||||
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ edit node
|
// {{{ magic readline!
|
||||||
|
|
||||||
function show_line(&$mm, $title, $cursor, $shift)
|
function magic_readline(&$mm, $title)
|
||||||
{
|
{
|
||||||
$output = mb_substr($title,$shift,$mm['terminal_width']-1);
|
|
||||||
$output .= str_repeat( ' ' ,$mm['terminal_width'] - mb_strlen($output) );
|
|
||||||
|
|
||||||
// showing the cursor
|
|
||||||
$output =
|
|
||||||
mb_substr
|
|
||||||
(
|
|
||||||
$output
|
|
||||||
,0
|
|
||||||
,$cursor-$shift-1
|
|
||||||
)
|
|
||||||
.invert_on
|
|
||||||
.mb_substr
|
|
||||||
(
|
|
||||||
$output
|
|
||||||
,$cursor-$shift-1
|
|
||||||
,1
|
|
||||||
)
|
|
||||||
.invert_off
|
|
||||||
.mb_substr
|
|
||||||
(
|
|
||||||
$output
|
|
||||||
,$cursor-$shift
|
|
||||||
);
|
|
||||||
|
|
||||||
put(0,$mm['terminal_height'],$mm['active_node_color'].$output);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function edit_node(&$mm, $rewrite = false)
|
|
||||||
{
|
|
||||||
$title = $rewrite ? '' : $mm['nodes'][ $mm['active_node'] ]['title'];
|
|
||||||
if ($mm['active_node']==0 && $title=='root') $title='';
|
|
||||||
|
|
||||||
$in = '';
|
$in = '';
|
||||||
$cursor = mb_strlen($title)+1;
|
$cursor = mb_strlen($title)+1;
|
||||||
$shift = max( 0, $cursor - $mm['terminal_width'] );
|
$shift = max( 0, $cursor - $mm['terminal_width'] );
|
||||||
|
@ -1164,7 +1130,7 @@ function edit_node(&$mm, $rewrite = false)
|
||||||
{
|
{
|
||||||
display($mm);
|
display($mm);
|
||||||
message($mm, 'Editing cancelled');
|
message($mm, 'Editing cancelled');
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// up arrow and home
|
// up arrow and home
|
||||||
|
@ -1269,18 +1235,7 @@ function edit_node(&$mm, $rewrite = false)
|
||||||
|
|
||||||
// enter
|
// enter
|
||||||
elseif ($in=="\012")
|
elseif ($in=="\012")
|
||||||
{
|
return trim($title);
|
||||||
$title = trim($title);
|
|
||||||
$mm['nodes'][ $mm['active_node'] ]['title'] = $title;
|
|
||||||
$original['nodes'][ $mm['active_node'] ]['title'] = $title;
|
|
||||||
|
|
||||||
push_change($mm);
|
|
||||||
$mm['modified'] = true;
|
|
||||||
|
|
||||||
build_map($mm);
|
|
||||||
display($mm);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ctrl+v
|
// ctrl+v
|
||||||
elseif ($in=="\026")
|
elseif ($in=="\026")
|
||||||
|
@ -1349,6 +1304,65 @@ function edit_node(&$mm, $rewrite = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function show_line(&$mm, $title, $cursor, $shift)
|
||||||
|
{
|
||||||
|
$output = mb_substr($title,$shift,$mm['terminal_width']-1);
|
||||||
|
$output .= str_repeat( ' ' ,$mm['terminal_width'] - mb_strlen($output) );
|
||||||
|
|
||||||
|
// showing the cursor
|
||||||
|
$output =
|
||||||
|
mb_substr
|
||||||
|
(
|
||||||
|
$output
|
||||||
|
,0
|
||||||
|
,$cursor-$shift-1
|
||||||
|
)
|
||||||
|
.invert_on
|
||||||
|
.mb_substr
|
||||||
|
(
|
||||||
|
$output
|
||||||
|
,$cursor-$shift-1
|
||||||
|
,1
|
||||||
|
)
|
||||||
|
.invert_off
|
||||||
|
.mb_substr
|
||||||
|
(
|
||||||
|
$output
|
||||||
|
,$cursor-$shift
|
||||||
|
);
|
||||||
|
|
||||||
|
put(0,$mm['terminal_height'],$mm['active_node_color'].$output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ edit node
|
||||||
|
|
||||||
|
function edit_node(&$mm, $rewrite = false)
|
||||||
|
{
|
||||||
|
$title = $rewrite ? '' : $mm['nodes'][ $mm['active_node'] ]['title'];
|
||||||
|
if ($mm['active_node']==0 && $title=='root') $title='';
|
||||||
|
|
||||||
|
$output = magic_readline($mm, $title);
|
||||||
|
|
||||||
|
if ($output === false)
|
||||||
|
{
|
||||||
|
display($mm);
|
||||||
|
message($mm, 'Editing cancelled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mm['nodes'][ $mm['active_node'] ]['title'] = $output;
|
||||||
|
|
||||||
|
push_change($mm);
|
||||||
|
$mm['modified'] = true;
|
||||||
|
|
||||||
|
build_map($mm);
|
||||||
|
display($mm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ center active node
|
// {{{ center active node
|
||||||
|
@ -1417,12 +1431,7 @@ function go_to_bottom(&$mm)
|
||||||
|
|
||||||
function search(&$mm)
|
function search(&$mm)
|
||||||
{
|
{
|
||||||
put(0,$mm['terminal_height'],$mm['active_node_color'].str_repeat(' ',$mm['terminal_width']));
|
$mm['query'] = magic_readline($mm,'');
|
||||||
move(0,$mm['terminal_height']);
|
|
||||||
|
|
||||||
system("stty sane");
|
|
||||||
$mm['query'] = readline('Search for: ');
|
|
||||||
system('stty cbreak -echo -crterase intr undef');
|
|
||||||
|
|
||||||
if (empty($mm['query']))
|
if (empty($mm['query']))
|
||||||
{
|
{
|
||||||
|
@ -1692,26 +1701,18 @@ function export_html_node(&$mm, $parent_id)
|
||||||
|
|
||||||
function save(&$mm, $new_name = false)
|
function save(&$mm, $new_name = false)
|
||||||
{
|
{
|
||||||
if (empty($mm['filename']))
|
if ($new_name || empty($mm['filename']))
|
||||||
$new_name = true;
|
|
||||||
|
|
||||||
if ($new_name)
|
|
||||||
{
|
{
|
||||||
$path = exec('pwd');
|
$new_name = magic_readline($mm, empty($mm['filename']) ? exec('pwd') : $mm['filename']);
|
||||||
put(0,$mm['terminal_height'],$mm['active_node_color'].str_repeat(' ',$mm['terminal_width']));
|
|
||||||
put(0,$mm['terminal_height']," $path -- new path and file name: ");
|
|
||||||
|
|
||||||
system("stty sane");
|
if ($new_name === false)
|
||||||
$mm['filename'] = trim(readline());
|
|
||||||
system('stty cbreak -echo');
|
|
||||||
|
|
||||||
if ($mm['filename']=='')
|
|
||||||
{
|
{
|
||||||
display($mm);
|
display($mm);
|
||||||
message($mm, 'Saving cancelled');
|
message($mm, 'Saving cancelled');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$mm['filename'] = $new_name;
|
||||||
$ext = mb_substr( $mm['filename'], mb_strrpos($mm['filename'],'.') + 1);
|
$ext = mb_substr( $mm['filename'], mb_strrpos($mm['filename'],'.') + 1);
|
||||||
|
|
||||||
if ($ext!='hmm')
|
if ($ext!='hmm')
|
||||||
|
|
Loading…
Reference in a new issue