@@ -558,6 +558,10 @@ static void finsh_thread_entry(void *parameter)
558558 * down key: 0x1b 0x5b 0x42
559559 * right key:0x1b 0x5b 0x43
560560 * left key: 0x1b 0x5b 0x44
561+ * home : 0x1b 0x5b 0x31 0x7E
562+ * insert : 0x1b 0x5b 0x32 0x7E
563+ * del : 0x1b 0x5b 0x33 0x7E
564+ * end : 0x1b 0x5b 0x34 0x7E
561565 */
562566 if (ch == 0x1b )
563567 {
@@ -676,6 +680,69 @@ static void finsh_thread_entry(void *parameter)
676680 }
677681 }
678682#endif /*defined(FINSH_USING_WORD_OPERATION) */
683+ #if defined(FINSH_USING_FUNC_EXT )
684+ else if (ch >= 0x31 && ch <= 0x34 ) /* home(0x31), insert(0x32), del(0x33), end(0x34) */
685+ {
686+ shell -> stat = WAIT_EXT_KEY ;
687+ shell -> line [shell -> line_position + 1 ] = ch ; /* store the key code */
688+ continue ;
689+ }
690+
691+ }
692+ else if (shell -> stat == WAIT_EXT_KEY )
693+ {
694+ shell -> stat = WAIT_NORMAL ;
695+
696+ if (ch == 0x7E ) /* extended key terminator */
697+ {
698+ rt_uint8_t key_code = shell -> line [shell -> line_position + 1 ];
699+
700+ if (key_code == 0x31 ) /* home key */
701+ {
702+ /* move cursor to beginning of line */
703+ while (shell -> line_curpos > 0 )
704+ {
705+ rt_kprintf ("\b" );
706+ shell -> line_curpos -- ;
707+ }
708+ }
709+ else if (key_code == 0x32 ) /* insert key */
710+ {
711+ /* toggle insert mode */
712+ shell -> overwrite_mode = !shell -> overwrite_mode ;
713+ }
714+ else if (key_code == 0x33 ) /* del key */
715+ {
716+ /* delete character at current cursor position */
717+ if (shell -> line_curpos < shell -> line_position )
718+ {
719+ int i ;
720+ shell -> line_position -- ;
721+ rt_memmove (& shell -> line [shell -> line_curpos ],
722+ & shell -> line [shell -> line_curpos + 1 ],
723+ shell -> line_position - shell -> line_curpos );
724+
725+ shell -> line [shell -> line_position ] = 0 ;
726+
727+ rt_kprintf ("%s " , & shell -> line [shell -> line_curpos ]);
728+
729+ /* move cursor back to original position */
730+ for (i = shell -> line_curpos ; i <= shell -> line_position ; i ++ )
731+ rt_kprintf ("\b" );
732+ }
733+ }
734+ else if (key_code == 0x34 ) /* end key */
735+ {
736+ /* move cursor to end of line */
737+ while (shell -> line_curpos < shell -> line_position )
738+ {
739+ rt_kprintf ("%c" , shell -> line [shell -> line_curpos ]);
740+ shell -> line_curpos ++ ;
741+ }
742+ }
743+ continue ;
744+ }
745+ #endif /*defined(FINSH_USING_FUNC_EXT) */
679746 }
680747
681748 /* received null or error */
@@ -789,28 +856,46 @@ static void finsh_thread_entry(void *parameter)
789856 if (shell -> line_curpos < shell -> line_position )
790857 {
791858 int i ;
859+ #if defined(FINSH_USING_FUNC_EXT )
860+ if (shell -> overwrite_mode ) /* overwrite mode */
861+ {
862+ /* directly overwrite the character */
863+ shell -> line [shell -> line_curpos ] = ch ;
864+ if (shell -> echo_mode )
865+ rt_kprintf ("%c" , ch );
866+ shell -> line_curpos ++ ;
867+ }
868+ else /* insert mode */
869+ #endif /*defined(FINSH_USING_FUNC_EXT)*/
870+ {
871+ shell -> line_position ++ ;
872+ /* move existing characters to the right */
873+ rt_memmove (& shell -> line [shell -> line_curpos + 1 ],
874+ & shell -> line [shell -> line_curpos ],
875+ shell -> line_position - shell -> line_curpos );
876+ shell -> line [shell -> line_curpos ] = ch ;
792877
793- rt_memmove (& shell -> line [shell -> line_curpos + 1 ],
794- & shell -> line [shell -> line_curpos ],
795- shell -> line_position - shell -> line_curpos );
796- shell -> line [shell -> line_curpos ] = ch ;
797- if (shell -> echo_mode )
798- rt_kprintf ("%s" , & shell -> line [shell -> line_curpos ]);
799-
800- /* move the cursor to new position */
801- for (i = shell -> line_curpos ; i < shell -> line_position ; i ++ )
802- rt_kprintf ("\b" );
878+ if (shell -> echo_mode )
879+ {
880+ rt_kprintf ("%s" , & shell -> line [shell -> line_curpos ]);
881+ /* move cursor back to correct position */
882+ for (i = shell -> line_curpos + 1 ; i < shell -> line_position ; i ++ )
883+ rt_kprintf ("\b" );
884+ }
885+ shell -> line_curpos ++ ;
886+ }
803887 }
804888 else
805889 {
890+ /* append character at end of line */
806891 shell -> line [shell -> line_position ] = ch ;
807892 if (shell -> echo_mode )
808893 rt_kprintf ("%c" , ch );
894+ shell -> line_position ++ ;
895+ shell -> line_curpos ++ ;
809896 }
810897
811898 ch = 0 ;
812- shell -> line_position ++ ;
813- shell -> line_curpos ++ ;
814899 if (shell -> line_position >= FINSH_CMD_SIZE )
815900 {
816901 /* clear command line */
0 commit comments