@@ -558,6 +558,10 @@ static void finsh_thread_entry(void *parameter)
558
558
* down key: 0x1b 0x5b 0x42
559
559
* right key:0x1b 0x5b 0x43
560
560
* 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
561
565
*/
562
566
if (ch == 0x1b )
563
567
{
@@ -676,6 +680,69 @@ static void finsh_thread_entry(void *parameter)
676
680
}
677
681
}
678
682
#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) */
679
746
}
680
747
681
748
/* received null or error */
@@ -789,28 +856,46 @@ static void finsh_thread_entry(void *parameter)
789
856
if (shell -> line_curpos < shell -> line_position )
790
857
{
791
858
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 ;
792
877
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
+ }
803
887
}
804
888
else
805
889
{
890
+ /* append character at end of line */
806
891
shell -> line [shell -> line_position ] = ch ;
807
892
if (shell -> echo_mode )
808
893
rt_kprintf ("%c" , ch );
894
+ shell -> line_position ++ ;
895
+ shell -> line_curpos ++ ;
809
896
}
810
897
811
898
ch = 0 ;
812
- shell -> line_position ++ ;
813
- shell -> line_curpos ++ ;
814
899
if (shell -> line_position >= FINSH_CMD_SIZE )
815
900
{
816
901
/* clear command line */
0 commit comments