make event handling forwards compatible and use constant generics to simplify parsing logic

macos-click-through
Keith Simmons 3 years ago
parent 69187642e4
commit 839f2938a1

@ -228,7 +228,7 @@ pub enum RedrawEvent {
bottom_line: f64, bottom_line: f64,
current_line: f64, current_line: f64,
current_column: f64, current_column: f64,
line_count: f64, line_count: Option<f64>,
}, },
CommandLineShow { CommandLineShow {
content: StyledContent, content: StyledContent,
@ -358,17 +358,38 @@ fn unpack_color(packed_color: u64) -> Color4f {
} }
} }
fn extract_values<Arr: AsMut<[Value]>>(values: Vec<Value>, mut arr: Arr) -> Result<Arr> { fn extract_values<const REQ: usize>(values: Vec<Value>) -> Result<[Value; REQ]> {
let arr_ref = arr.as_mut(); if REQ > values.len() {
Err(ParseError::Format(format!("{:?}", values)))
} else {
let mut required_values = vec![Value::Nil; REQ];
if values.len() != arr_ref.len() { for (index, value) in values.into_iter().enumerate() {
if index < REQ {
required_values[index] = value;
}
}
Ok(required_values.try_into().unwrap())
}
}
fn extract_values_with_optional<const REQ: usize, const OPT: usize>(values: Vec<Value>) -> Result<([Value; REQ], [Option<Value>; OPT])> {
if REQ > values.len() {
Err(ParseError::Format(format!("{:?}", values))) Err(ParseError::Format(format!("{:?}", values)))
} else { } else {
for (i, val) in values.into_iter().enumerate() { let mut required_values = vec![Value::Nil; REQ];
arr_ref[i] = val; let mut optional_values = vec![None; OPT];
for (index, value) in values.into_iter().enumerate() {
if index < REQ {
required_values[index] = value;
} else {
optional_values[index - REQ] = Some(value);
}
} }
Ok(arr) Ok((required_values.try_into().unwrap(), optional_values.try_into().unwrap()))
} }
} }
@ -401,7 +422,7 @@ fn parse_bool(bool_value: Value) -> Result<bool> {
} }
fn parse_set_title(set_title_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_set_title(set_title_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [title] = extract_values(set_title_arguments, [Value::Nil])?; let [title] = extract_values(set_title_arguments)?;
Ok(RedrawEvent::SetTitle { Ok(RedrawEvent::SetTitle {
title: parse_string(title)?, title: parse_string(title)?,
@ -410,7 +431,7 @@ fn parse_set_title(set_title_arguments: Vec<Value>) -> Result<RedrawEvent> {
fn parse_mode_info_set(mode_info_set_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_mode_info_set(mode_info_set_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [_cursor_style_enabled, mode_info] = let [_cursor_style_enabled, mode_info] =
extract_values(mode_info_set_arguments, [Value::Nil, Value::Nil])?; extract_values(mode_info_set_arguments)?;
let mode_info_values = parse_array(mode_info)?; let mode_info_values = parse_array(mode_info)?;
let mut cursor_modes = Vec::with_capacity(mode_info_values.len()); let mut cursor_modes = Vec::with_capacity(mode_info_values.len());
@ -450,7 +471,7 @@ fn parse_mode_info_set(mode_info_set_arguments: Vec<Value>) -> Result<RedrawEven
} }
fn parse_option_set(option_set_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_option_set(option_set_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [name, value] = extract_values(option_set_arguments, [Value::Nil, Value::Nil])?; let [name, value] = extract_values(option_set_arguments)?;
let name = parse_string(name)?; let name = parse_string(name)?;
@ -472,7 +493,7 @@ fn parse_option_set(option_set_arguments: Vec<Value>) -> Result<RedrawEvent> {
} }
fn parse_mode_change(mode_change_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_mode_change(mode_change_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [mode, mode_index] = extract_values(mode_change_arguments, [Value::Nil, Value::Nil])?; let [mode, mode_index] = extract_values(mode_change_arguments)?;
let mode_name = parse_string(mode)?; let mode_name = parse_string(mode)?;
Ok(RedrawEvent::ModeChange { Ok(RedrawEvent::ModeChange {
@ -490,7 +511,7 @@ fn parse_mode_change(mode_change_arguments: Vec<Value>) -> Result<RedrawEvent> {
fn parse_grid_resize(grid_resize_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_grid_resize(grid_resize_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [grid_id, width, height] = let [grid_id, width, height] =
extract_values(grid_resize_arguments, [Value::Nil, Value::Nil, Value::Nil])?; extract_values(grid_resize_arguments)?;
Ok(RedrawEvent::Resize { Ok(RedrawEvent::Resize {
grid: parse_u64(grid_id)?, grid: parse_u64(grid_id)?,
@ -500,9 +521,8 @@ fn parse_grid_resize(grid_resize_arguments: Vec<Value>) -> Result<RedrawEvent> {
} }
fn parse_default_colors(default_colors_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_default_colors(default_colors_arguments: Vec<Value>) -> Result<RedrawEvent> {
let values = [Value::Nil, Value::Nil, Value::Nil, Value::Nil, Value::Nil];
let [foreground, background, special, _term_foreground, _term_background] = let [foreground, background, special, _term_foreground, _term_background] =
extract_values(default_colors_arguments, values)?; extract_values(default_colors_arguments)?;
Ok(RedrawEvent::DefaultColorsSet { Ok(RedrawEvent::DefaultColorsSet {
colors: Colors { colors: Colors {
@ -550,9 +570,8 @@ fn parse_style(style_map: Value) -> Result<Style> {
} }
fn parse_hl_attr_define(hl_attr_define_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_hl_attr_define(hl_attr_define_arguments: Vec<Value>) -> Result<RedrawEvent> {
let values = [Value::Nil, Value::Nil, Value::Nil, Value::Nil];
let [id, attributes, _terminal_attributes, _info] = let [id, attributes, _terminal_attributes, _info] =
extract_values(hl_attr_define_arguments, values)?; extract_values(hl_attr_define_arguments)?;
let style = parse_style(attributes)?; let style = parse_style(attributes)?;
Ok(RedrawEvent::HighlightAttributesDefine { Ok(RedrawEvent::HighlightAttributesDefine {
@ -592,8 +611,7 @@ fn parse_grid_line_cell(grid_line_cell: Value) -> Result<GridLineCell> {
} }
fn parse_grid_line(grid_line_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_grid_line(grid_line_arguments: Vec<Value>) -> Result<RedrawEvent> {
let values = [Value::Nil, Value::Nil, Value::Nil, Value::Nil]; let [grid_id, row, column_start, cells] = extract_values(grid_line_arguments)?;
let [grid_id, row, column_start, cells] = extract_values(grid_line_arguments, values)?;
Ok(RedrawEvent::GridLine { Ok(RedrawEvent::GridLine {
grid: parse_u64(grid_id)?, grid: parse_u64(grid_id)?,
@ -607,7 +625,7 @@ fn parse_grid_line(grid_line_arguments: Vec<Value>) -> Result<RedrawEvent> {
} }
fn parse_grid_clear(grid_clear_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_grid_clear(grid_clear_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [grid_id] = extract_values(grid_clear_arguments, [Value::Nil])?; let [grid_id] = extract_values(grid_clear_arguments)?;
Ok(RedrawEvent::Clear { Ok(RedrawEvent::Clear {
grid: parse_u64(grid_id)?, grid: parse_u64(grid_id)?,
@ -615,7 +633,7 @@ fn parse_grid_clear(grid_clear_arguments: Vec<Value>) -> Result<RedrawEvent> {
} }
fn parse_grid_destroy(grid_destroy_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_grid_destroy(grid_destroy_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [grid_id] = extract_values(grid_destroy_arguments, [Value::Nil])?; let [grid_id] = extract_values(grid_destroy_arguments)?;
Ok(RedrawEvent::Destroy { Ok(RedrawEvent::Destroy {
grid: parse_u64(grid_id)?, grid: parse_u64(grid_id)?,
@ -624,7 +642,7 @@ fn parse_grid_destroy(grid_destroy_arguments: Vec<Value>) -> Result<RedrawEvent>
fn parse_grid_cursor_goto(cursor_goto_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_grid_cursor_goto(cursor_goto_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [grid_id, row, column] = let [grid_id, row, column] =
extract_values(cursor_goto_arguments, [Value::Nil, Value::Nil, Value::Nil])?; extract_values(cursor_goto_arguments)?;
Ok(RedrawEvent::CursorGoto { Ok(RedrawEvent::CursorGoto {
grid: parse_u64(grid_id)?, grid: parse_u64(grid_id)?,
@ -634,17 +652,8 @@ fn parse_grid_cursor_goto(cursor_goto_arguments: Vec<Value>) -> Result<RedrawEve
} }
fn parse_grid_scroll(grid_scroll_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_grid_scroll(grid_scroll_arguments: Vec<Value>) -> Result<RedrawEvent> {
let values = [
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
];
let [grid_id, top, bottom, left, right, rows, columns] = let [grid_id, top, bottom, left, right, rows, columns] =
extract_values(grid_scroll_arguments, values)?; extract_values(grid_scroll_arguments)?;
Ok(RedrawEvent::Scroll { Ok(RedrawEvent::Scroll {
grid: parse_u64(grid_id)?, grid: parse_u64(grid_id)?,
top: parse_u64(top)?, top: parse_u64(top)?,
@ -657,16 +666,8 @@ fn parse_grid_scroll(grid_scroll_arguments: Vec<Value>) -> Result<RedrawEvent> {
} }
fn parse_win_pos(win_pos_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_win_pos(win_pos_arguments: Vec<Value>) -> Result<RedrawEvent> {
let values = [
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
];
let [grid, _window, start_row, start_column, width, height] = let [grid, _window, start_row, start_column, width, height] =
extract_values(win_pos_arguments, values)?; extract_values(win_pos_arguments)?;
Ok(RedrawEvent::WindowPosition { Ok(RedrawEvent::WindowPosition {
grid: parse_u64(grid)?, grid: parse_u64(grid)?,
@ -689,43 +690,14 @@ fn parse_window_anchor(value: Value) -> Result<WindowAnchor> {
} }
fn parse_win_float_pos(win_float_pos_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_win_float_pos(win_float_pos_arguments: Vec<Value>) -> Result<RedrawEvent> {
if win_float_pos_arguments.len() == 8 { let ([grid, _window, anchor, anchor_grid, anchor_row, anchor_column, focusable], [sort_order]) =
let values = [ extract_values_with_optional(win_float_pos_arguments)?;
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
];
let [grid, _window, anchor, anchor_grid, anchor_row, anchor_column, focusable, sort_order] =
extract_values(win_float_pos_arguments, values)?;
Ok(RedrawEvent::WindowFloatPosition { let sort_order = if let Some(sort_order) = sort_order {
grid: parse_u64(grid)?, Some(parse_u64(sort_order)?)
anchor: parse_window_anchor(anchor)?,
anchor_grid: parse_u64(anchor_grid)?,
anchor_row: parse_f64(anchor_row)?,
anchor_column: parse_f64(anchor_column)?,
focusable: parse_bool(focusable)?,
sort_order: Some(parse_u64(sort_order)?),
})
} else { } else {
let values = [ None
Value::Nil, };
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
];
let [grid, _window, anchor, anchor_grid, anchor_row, anchor_column, focusable] =
extract_values(win_float_pos_arguments, values)?;
Ok(RedrawEvent::WindowFloatPosition { Ok(RedrawEvent::WindowFloatPosition {
grid: parse_u64(grid)?, grid: parse_u64(grid)?,
@ -734,13 +706,12 @@ fn parse_win_float_pos(win_float_pos_arguments: Vec<Value>) -> Result<RedrawEven
anchor_row: parse_f64(anchor_row)?, anchor_row: parse_f64(anchor_row)?,
anchor_column: parse_f64(anchor_column)?, anchor_column: parse_f64(anchor_column)?,
focusable: parse_bool(focusable)?, focusable: parse_bool(focusable)?,
sort_order: None, sort_order: sort_order,
}) })
} }
}
fn parse_win_external_pos(win_external_pos_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_win_external_pos(win_external_pos_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [grid, _window] = extract_values(win_external_pos_arguments, [Value::Nil, Value::Nil])?; let [grid, _window] = extract_values(win_external_pos_arguments)?;
Ok(RedrawEvent::WindowExternalPosition { Ok(RedrawEvent::WindowExternalPosition {
grid: parse_u64(grid)?, grid: parse_u64(grid)?,
@ -748,7 +719,7 @@ fn parse_win_external_pos(win_external_pos_arguments: Vec<Value>) -> Result<Redr
} }
fn parse_win_hide(win_hide_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_win_hide(win_hide_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [grid] = extract_values(win_hide_arguments, [Value::Nil])?; let [grid] = extract_values(win_hide_arguments)?;
Ok(RedrawEvent::WindowHide { Ok(RedrawEvent::WindowHide {
grid: parse_u64(grid)?, grid: parse_u64(grid)?,
@ -756,7 +727,7 @@ fn parse_win_hide(win_hide_arguments: Vec<Value>) -> Result<RedrawEvent> {
} }
fn parse_win_close(win_close_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_win_close(win_close_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [grid] = extract_values(win_close_arguments, [Value::Nil])?; let [grid] = extract_values(win_close_arguments)?;
Ok(RedrawEvent::WindowClose { Ok(RedrawEvent::WindowClose {
grid: parse_u64(grid)?, grid: parse_u64(grid)?,
@ -764,8 +735,7 @@ fn parse_win_close(win_close_arguments: Vec<Value>) -> Result<RedrawEvent> {
} }
fn parse_msg_set_pos(msg_set_pos_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_msg_set_pos(msg_set_pos_arguments: Vec<Value>) -> Result<RedrawEvent> {
let values = [Value::Nil, Value::Nil, Value::Nil, Value::Nil]; let [grid, row, scrolled, separator_character] = extract_values(msg_set_pos_arguments)?;
let [grid, row, scrolled, separator_character] = extract_values(msg_set_pos_arguments, values)?;
Ok(RedrawEvent::MessageSetPosition { Ok(RedrawEvent::MessageSetPosition {
grid: parse_u64(grid)?, grid: parse_u64(grid)?,
@ -776,17 +746,14 @@ fn parse_msg_set_pos(msg_set_pos_arguments: Vec<Value>) -> Result<RedrawEvent> {
} }
fn parse_win_viewport(win_viewport_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_win_viewport(win_viewport_arguments: Vec<Value>) -> Result<RedrawEvent> {
let values = [ let ([grid, _window, top_line, bottom_line, current_line, current_column], [line_count]) =
Value::Nil, extract_values_with_optional(win_viewport_arguments)?;
Value::Nil,
Value::Nil, let line_count = if let Some(line_count) = line_count {
Value::Nil, Some(parse_f64(line_count)?)
Value::Nil, } else {
Value::Nil, None
Value::Nil, };
];
let [grid, _window, top_line, bottom_line, current_line, current_column, line_count] =
extract_values(win_viewport_arguments, values)?;
Ok(RedrawEvent::WindowViewport { Ok(RedrawEvent::WindowViewport {
grid: parse_u64(grid)?, grid: parse_u64(grid)?,
@ -794,7 +761,7 @@ fn parse_win_viewport(win_viewport_arguments: Vec<Value>) -> Result<RedrawEvent>
bottom_line: parse_f64(bottom_line)?, bottom_line: parse_f64(bottom_line)?,
current_line: parse_f64(current_line)?, current_line: parse_f64(current_line)?,
current_column: parse_f64(current_column)?, current_column: parse_f64(current_column)?,
line_count: parse_f64(line_count)?, line_count,
}) })
} }
@ -802,7 +769,7 @@ fn parse_styled_content(line: Value) -> Result<StyledContent> {
parse_array(line)? parse_array(line)?
.into_iter() .into_iter()
.map(|tuple| { .map(|tuple| {
let [style_id, text] = extract_values(parse_array(tuple)?, [Value::Nil, Value::Nil])?; let [style_id, text] = extract_values(parse_array(tuple)?)?;
Ok((parse_u64(style_id)?, parse_string(text)?)) Ok((parse_u64(style_id)?, parse_string(text)?))
}) })
@ -810,16 +777,8 @@ fn parse_styled_content(line: Value) -> Result<StyledContent> {
} }
fn parse_cmdline_show(cmdline_show_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_cmdline_show(cmdline_show_arguments: Vec<Value>) -> Result<RedrawEvent> {
let values = [
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
Value::Nil,
];
let [content, position, first_character, prompt, indent, level] = let [content, position, first_character, prompt, indent, level] =
extract_values(cmdline_show_arguments, values)?; extract_values(cmdline_show_arguments)?;
Ok(RedrawEvent::CommandLineShow { Ok(RedrawEvent::CommandLineShow {
content: parse_styled_content(content)?, content: parse_styled_content(content)?,
@ -832,7 +791,7 @@ fn parse_cmdline_show(cmdline_show_arguments: Vec<Value>) -> Result<RedrawEvent>
} }
fn parse_cmdline_pos(cmdline_pos_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_cmdline_pos(cmdline_pos_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [position, level] = extract_values(cmdline_pos_arguments, [Value::Nil, Value::Nil])?; let [position, level] = extract_values(cmdline_pos_arguments)?;
Ok(RedrawEvent::CommandLinePosition { Ok(RedrawEvent::CommandLinePosition {
position: parse_u64(position)?, position: parse_u64(position)?,
@ -843,7 +802,6 @@ fn parse_cmdline_pos(cmdline_pos_arguments: Vec<Value>) -> Result<RedrawEvent> {
fn parse_cmdline_special_char(cmdline_special_char_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_cmdline_special_char(cmdline_special_char_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [character, shift, level] = extract_values( let [character, shift, level] = extract_values(
cmdline_special_char_arguments, cmdline_special_char_arguments,
[Value::Nil, Value::Nil, Value::Nil],
)?; )?;
Ok(RedrawEvent::CommandLineSpecialCharacter { Ok(RedrawEvent::CommandLineSpecialCharacter {
@ -854,7 +812,7 @@ fn parse_cmdline_special_char(cmdline_special_char_arguments: Vec<Value>) -> Res
} }
fn parse_cmdline_block_show(cmdline_block_show_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_cmdline_block_show(cmdline_block_show_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [lines] = extract_values(cmdline_block_show_arguments, [Value::Nil])?; let [lines] = extract_values(cmdline_block_show_arguments)?;
Ok(RedrawEvent::CommandLineBlockShow { Ok(RedrawEvent::CommandLineBlockShow {
lines: parse_array(lines)? lines: parse_array(lines)?
@ -865,7 +823,7 @@ fn parse_cmdline_block_show(cmdline_block_show_arguments: Vec<Value>) -> Result<
} }
fn parse_cmdline_block_append(cmdline_block_append_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_cmdline_block_append(cmdline_block_append_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [line] = extract_values(cmdline_block_append_arguments, [Value::Nil])?; let [line] = extract_values(cmdline_block_append_arguments)?;
Ok(RedrawEvent::CommandLineBlockAppend { Ok(RedrawEvent::CommandLineBlockAppend {
line: parse_styled_content(line)?, line: parse_styled_content(line)?,
@ -874,7 +832,7 @@ fn parse_cmdline_block_append(cmdline_block_append_arguments: Vec<Value>) -> Res
fn parse_msg_show(msg_show_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_msg_show(msg_show_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [kind, content, replace_last] = let [kind, content, replace_last] =
extract_values(msg_show_arguments, [Value::Nil, Value::Nil, Value::Nil])?; extract_values(msg_show_arguments)?;
Ok(RedrawEvent::MessageShow { Ok(RedrawEvent::MessageShow {
kind: MessageKind::parse(&parse_string(kind)?), kind: MessageKind::parse(&parse_string(kind)?),
@ -884,7 +842,7 @@ fn parse_msg_show(msg_show_arguments: Vec<Value>) -> Result<RedrawEvent> {
} }
fn parse_msg_showmode(msg_showmode_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_msg_showmode(msg_showmode_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [content] = extract_values(msg_showmode_arguments, [Value::Nil])?; let [content] = extract_values(msg_showmode_arguments)?;
Ok(RedrawEvent::MessageShowMode { Ok(RedrawEvent::MessageShowMode {
content: parse_styled_content(content)?, content: parse_styled_content(content)?,
@ -892,7 +850,7 @@ fn parse_msg_showmode(msg_showmode_arguments: Vec<Value>) -> Result<RedrawEvent>
} }
fn parse_msg_showcmd(msg_showcmd_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_msg_showcmd(msg_showcmd_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [content] = extract_values(msg_showcmd_arguments, [Value::Nil])?; let [content] = extract_values(msg_showcmd_arguments)?;
Ok(RedrawEvent::MessageShowCommand { Ok(RedrawEvent::MessageShowCommand {
content: parse_styled_content(content)?, content: parse_styled_content(content)?,
@ -900,7 +858,7 @@ fn parse_msg_showcmd(msg_showcmd_arguments: Vec<Value>) -> Result<RedrawEvent> {
} }
fn parse_msg_ruler(msg_ruler_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_msg_ruler(msg_ruler_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [content] = extract_values(msg_ruler_arguments, [Value::Nil])?; let [content] = extract_values(msg_ruler_arguments)?;
Ok(RedrawEvent::MessageRuler { Ok(RedrawEvent::MessageRuler {
content: parse_styled_content(content)?, content: parse_styled_content(content)?,
@ -908,7 +866,7 @@ fn parse_msg_ruler(msg_ruler_arguments: Vec<Value>) -> Result<RedrawEvent> {
} }
fn parse_msg_history_entry(entry: Value) -> Result<(MessageKind, StyledContent)> { fn parse_msg_history_entry(entry: Value) -> Result<(MessageKind, StyledContent)> {
let [kind, content] = extract_values(parse_array(entry)?, [Value::Nil, Value::Nil])?; let [kind, content] = extract_values(parse_array(entry)?)?;
Ok(( Ok((
MessageKind::parse(&parse_string(kind)?), MessageKind::parse(&parse_string(kind)?),
@ -917,7 +875,7 @@ fn parse_msg_history_entry(entry: Value) -> Result<(MessageKind, StyledContent)>
} }
fn parse_msg_history_show(msg_history_show_arguments: Vec<Value>) -> Result<RedrawEvent> { fn parse_msg_history_show(msg_history_show_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [entries] = extract_values(msg_history_show_arguments, [Value::Nil])?; let [entries] = extract_values(msg_history_show_arguments)?;
Ok(RedrawEvent::MessageHistoryShow { Ok(RedrawEvent::MessageHistoryShow {
entries: parse_array(entries)? entries: parse_array(entries)?

Loading…
Cancel
Save