Add repeat functionality
This commit is contained in:
		
							parent
							
								
									c2bd680299
								
							
						
					
					
						commit
						c117482d4f
					
				@ -25,7 +25,7 @@ fn reentrant_command_handler(
 | 
				
			|||||||
        match command.split_out_command() {
 | 
					        match command.split_out_command() {
 | 
				
			||||||
            None => (),
 | 
					            None => (),
 | 
				
			||||||
            Some((cmd, rest)) => {
 | 
					            Some((cmd, rest)) => {
 | 
				
			||||||
                if cmd.starts_with('#') {
 | 
					                if let ("#", command_rest) = cmd.split_at(1) {
 | 
				
			||||||
                    if cmd == "##" {
 | 
					                    if cmd == "##" {
 | 
				
			||||||
                        match lua_state.execute(debrace(&join(rest.arguments.iter(), " "))) {
 | 
					                        match lua_state.execute(debrace(&join(rest.arguments.iter(), " "))) {
 | 
				
			||||||
                            Ok(()) => (),
 | 
					                            Ok(()) => (),
 | 
				
			||||||
@ -34,9 +34,17 @@ fn reentrant_command_handler(
 | 
				
			|||||||
                                    .unwrap_or(())
 | 
					                                    .unwrap_or(())
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					                    } else if let Ok(repeat_count) = command_rest.parse::<u16>() {
 | 
				
			||||||
 | 
					                        for _ in 0..repeat_count {
 | 
				
			||||||
 | 
					                            reentrant_command_handler(
 | 
				
			||||||
 | 
					                                lua_state,
 | 
				
			||||||
 | 
					                                globals,
 | 
				
			||||||
 | 
					                                term_frame,
 | 
				
			||||||
 | 
					                                &join(rest.arguments.iter(), " "),
 | 
				
			||||||
 | 
					                            );
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                        let cmd = &cmd[1..];
 | 
					                        match lua_state.execute_command(command_rest, &rest.arguments) {
 | 
				
			||||||
                        match lua_state.execute_command(cmd, &rest.arguments) {
 | 
					 | 
				
			||||||
                            Ok(()) => (),
 | 
					                            Ok(()) => (),
 | 
				
			||||||
                            Err(msg) => {
 | 
					                            Err(msg) => {
 | 
				
			||||||
                                echo_to_term_frame(globals, term_frame, &format!("{}\r\n", msg))
 | 
					                                echo_to_term_frame(globals, term_frame, &format!("{}\r\n", msg))
 | 
				
			||||||
 | 
				
			|||||||
@ -58,8 +58,11 @@ impl LuaState {
 | 
				
			|||||||
            .try_enter(|ctx| {
 | 
					            .try_enter(|ctx| {
 | 
				
			||||||
                let commands =
 | 
					                let commands =
 | 
				
			||||||
                    Table::from_value(ctx, ctx.get_global(ctx.intern_static(b"commands")))?;
 | 
					                    Table::from_value(ctx, ctx.get_global(ctx.intern_static(b"commands")))?;
 | 
				
			||||||
                let command_fn =
 | 
					                let command_value: Value = commands.get(ctx, ctx.intern(command.as_bytes()));
 | 
				
			||||||
                    Function::from_value(ctx, commands.get(ctx, ctx.intern(command.as_bytes())))?;
 | 
					                if command_value.is_nil() {
 | 
				
			||||||
 | 
					                    Err(anyhow::Error::msg("Unknown command"))?;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                let command_fn = Function::from_value(ctx, command_value)?;
 | 
				
			||||||
                ctx.fetch(&self.exec).restart(
 | 
					                ctx.fetch(&self.exec).restart(
 | 
				
			||||||
                    ctx,
 | 
					                    ctx,
 | 
				
			||||||
                    command_fn,
 | 
					                    command_fn,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user