@@ -1438,155 +1438,153 @@ void shell_init(void) {
14381438
14391439void shell_on_input (int key ) {
14401440 int ch = key ;
1441- {
1442- if (ch == 12 ) {
1443- fb_clear (0 );
1444- fb_console_init (0xFFFFFF , 0 );
1445- line_length = 0 ;
1446- cursor_pos = 0 ;
1447- shell_prompt ();
1448- continue ;
1449- }
1450- if (ch == 21 ) {
1451- line_length = 0 ;
1452- cursor_pos = 0 ;
1453- shell_redraw_line ();
1454- continue ;
1441+ if (ch == 12 ) {
1442+ fb_clear (0 );
1443+ fb_console_init (0xFFFFFF , 0 );
1444+ line_length = 0 ;
1445+ cursor_pos = 0 ;
1446+ shell_prompt ();
1447+ return ;
1448+ }
1449+ if (ch == 21 ) {
1450+ line_length = 0 ;
1451+ cursor_pos = 0 ;
1452+ shell_redraw_line ();
1453+ return ;
1454+ }
1455+ if (ch == 1 ) {
1456+ while (cursor_pos > 0 ) {
1457+ cursor_pos -- ;
1458+ shell_putc ('\b' );
14551459 }
1456- if ( ch == 1 ) {
1457- while ( cursor_pos > 0 ) {
1458- cursor_pos -- ;
1459- shell_putc ( '\b' );
1460- }
1461- continue ;
1460+ return ;
1461+ }
1462+ if ( ch == 5 ) {
1463+ while ( cursor_pos < line_length ) {
1464+ shell_putc ( line_buffer [ cursor_pos ]);
1465+ cursor_pos ++ ;
14621466 }
1463- if ( ch == 5 ) {
1464- while ( cursor_pos < line_length ) {
1465- shell_putc ( line_buffer [ cursor_pos ]);
1466- cursor_pos ++ ;
1467- }
1468- continue ;
1467+ return ;
1468+ }
1469+ if ( ch == 2 ) {
1470+ if ( cursor_pos > 0 ) {
1471+ cursor_pos -- ;
1472+ shell_putc ( '\b' ) ;
14691473 }
1470- if ( ch == 2 ) {
1471- if ( cursor_pos > 0 ) {
1472- cursor_pos -- ;
1473- shell_putc ( '\b' );
1474- }
1475- continue ;
1474+ return ;
1475+ }
1476+ if ( ch == 6 ) {
1477+ if ( cursor_pos < line_length ) {
1478+ shell_putc ( line_buffer [ cursor_pos ]);
1479+ cursor_pos ++ ;
14761480 }
1477- if (ch == 6 ) {
1478- if (cursor_pos < line_length ) {
1479- shell_putc (line_buffer [cursor_pos ]);
1480- cursor_pos ++ ;
1481+ return ;
1482+ }
1483+ if (ch == 4 ) {
1484+ if (cursor_pos < line_length ) {
1485+ for (uint32_t i = cursor_pos ; i + 1 < line_length ; ++ i ) {
1486+ line_buffer [i ] = line_buffer [i + 1 ];
14811487 }
1482- continue ;
1488+ line_length -- ;
1489+ shell_redraw_line ();
14831490 }
1484- if (ch == 4 ) {
1485- if (cursor_pos < line_length ) {
1486- for (uint32_t i = cursor_pos ; i + 1 < line_length ; ++ i ) {
1487- line_buffer [i ] = line_buffer [i + 1 ];
1488- }
1489- line_length -- ;
1490- shell_redraw_line ();
1491- }
1492- continue ;
1491+ return ;
1492+ }
1493+ if (ch == KEY_ARROW_UP || ch == 16 ) {
1494+ if (history_count > 0 && history_index > 0 ) {
1495+ history_index -- ;
1496+ shell_set_line (history_at (history_index ));
14931497 }
1494- if (ch == KEY_ARROW_UP || ch == 16 ) {
1495- if (history_count > 0 && history_index > 0 ) {
1496- history_index -- ;
1497- shell_set_line (history_at (history_index ));
1498- }
1499- continue ;
1498+ return ;
1499+ }
1500+ if (ch == KEY_ARROW_DOWN || ch == 14 ) {
1501+ if (history_index + 1 < history_count ) {
1502+ history_index ++ ;
1503+ shell_set_line (history_at (history_index ));
1504+ } else if (history_index < history_count ) {
1505+ history_index = history_count ;
1506+ line_length = 0 ;
1507+ cursor_pos = 0 ;
1508+ shell_redraw_line ();
15001509 }
1501- if (ch == KEY_ARROW_DOWN || ch == 14 ) {
1502- if (history_index + 1 < history_count ) {
1503- history_index ++ ;
1504- shell_set_line (history_at (history_index ));
1505- } else if (history_index < history_count ) {
1506- history_index = history_count ;
1507- line_length = 0 ;
1508- cursor_pos = 0 ;
1509- shell_redraw_line ();
1510- }
1511- continue ;
1510+ return ;
1511+ }
1512+ if (ch == KEY_ARROW_LEFT ) {
1513+ if (cursor_pos > 0 ) {
1514+ cursor_pos -- ;
1515+ shell_putc ('\b' );
15121516 }
1513- if ( ch == KEY_ARROW_LEFT ) {
1514- if ( cursor_pos > 0 ) {
1515- cursor_pos -- ;
1516- shell_putc ( '\b' );
1517- }
1518- continue ;
1517+ return ;
1518+ }
1519+ if ( ch == KEY_ARROW_RIGHT ) {
1520+ if ( cursor_pos < line_length ) {
1521+ shell_putc ( line_buffer [ cursor_pos ]);
1522+ cursor_pos ++ ;
15191523 }
1520- if (ch == KEY_ARROW_RIGHT ) {
1521- if (cursor_pos < line_length ) {
1522- shell_putc (line_buffer [cursor_pos ]);
1523- cursor_pos ++ ;
1524+ return ;
1525+ }
1526+ if (ch == KEY_DELETE ) {
1527+ if (cursor_pos < line_length ) {
1528+ for (uint32_t i = cursor_pos ; i + 1 < line_length ; ++ i ) {
1529+ line_buffer [i ] = line_buffer [i + 1 ];
15241530 }
1525- continue ;
1531+ line_length -- ;
1532+ shell_redraw_line ();
15261533 }
1527- if (ch == KEY_DELETE ) {
1528- if (cursor_pos < line_length ) {
1529- for (uint32_t i = cursor_pos ; i + 1 < line_length ; ++ i ) {
1530- line_buffer [i ] = line_buffer [i + 1 ];
1531- }
1532- line_length -- ;
1533- shell_redraw_line ();
1534+ return ;
1535+ }
1536+ if (ch == KEY_PAGE_UP ) {
1537+ fb_console_scroll (5 );
1538+ return ;
1539+ }
1540+ if (ch == KEY_PAGE_DOWN ) {
1541+ fb_console_scroll (-5 );
1542+ return ;
1543+ }
1544+ if (ch == '\n' ) {
1545+ shell_putc ('\n' );
1546+ if (line_length > 0 ) {
1547+ uint32_t slot = history_head ;
1548+ for (uint32_t i = 0 ; i < line_length && i + 1 < SHELL_LINE_SIZE ; ++ i ) {
1549+ history [slot ][i ] = line_buffer [i ];
15341550 }
1535- continue ;
1536- }
1537- if (ch == KEY_PAGE_UP ) {
1538- fb_console_scroll (5 );
1539- continue ;
1540- }
1541- if (ch == KEY_PAGE_DOWN ) {
1542- fb_console_scroll (-5 );
1543- continue ;
1544- }
1545- if (ch == '\n' ) {
1546- shell_putc ('\n' );
1547- if (line_length > 0 ) {
1548- uint32_t slot = history_head ;
1549- for (uint32_t i = 0 ; i < line_length && i + 1 < SHELL_LINE_SIZE ; ++ i ) {
1550- history [slot ][i ] = line_buffer [i ];
1551- }
1552- history [slot ][line_length ] = 0 ;
1553- history_head = (history_head + 1 ) % SHELL_HISTORY ;
1554- if (history_count < SHELL_HISTORY ) {
1555- history_count ++ ;
1556- }
1557- history_index = history_count ;
1551+ history [slot ][line_length ] = 0 ;
1552+ history_head = (history_head + 1 ) % SHELL_HISTORY ;
1553+ if (history_count < SHELL_HISTORY ) {
1554+ history_count ++ ;
15581555 }
1559- line_buffer [line_length ] = 0 ;
1560- shell_execute_line ();
1561- line_length = 0 ;
1562- cursor_pos = 0 ;
1563- shell_prompt ();
1564- continue ;
1565- }
1566- if (ch == '\t' ) {
1567- shell_autocomplete ();
1568- continue ;
1556+ history_index = history_count ;
15691557 }
1570- if (ch == '\b' ) {
1571- if (cursor_pos > 0 ) {
1572- for (uint32_t i = cursor_pos - 1 ; i + 1 < line_length ; ++ i ) {
1573- line_buffer [i ] = line_buffer [i + 1 ];
1574- }
1575- line_length -- ;
1576- cursor_pos -- ;
1577- shell_redraw_line ();
1558+ line_buffer [line_length ] = 0 ;
1559+ shell_execute_line ();
1560+ line_length = 0 ;
1561+ cursor_pos = 0 ;
1562+ shell_prompt ();
1563+ return ;
1564+ }
1565+ if (ch == '\t' ) {
1566+ shell_autocomplete ();
1567+ return ;
1568+ }
1569+ if (ch == '\b' ) {
1570+ if (cursor_pos > 0 ) {
1571+ for (uint32_t i = cursor_pos - 1 ; i + 1 < line_length ; ++ i ) {
1572+ line_buffer [i ] = line_buffer [i + 1 ];
15781573 }
1579- continue ;
1580- }
1581- if (line_length + 1 >= SHELL_LINE_SIZE ) {
1582- continue ;
1583- }
1584- for (uint32_t i = line_length ; i > cursor_pos ; -- i ) {
1585- line_buffer [i ] = line_buffer [i - 1 ];
1574+ line_length -- ;
1575+ cursor_pos -- ;
1576+ shell_redraw_line ();
15861577 }
1587- line_buffer [ cursor_pos ] = ( char ) ch ;
1588- line_length ++ ;
1589- cursor_pos ++ ;
1590- shell_redraw_line () ;
1578+ return ;
1579+ }
1580+ if ( line_length + 1 >= SHELL_LINE_SIZE ) {
1581+ return ;
15911582 }
1583+ for (uint32_t i = line_length ; i > cursor_pos ; -- i ) {
1584+ line_buffer [i ] = line_buffer [i - 1 ];
1585+ }
1586+ line_buffer [cursor_pos ] = (char )ch ;
1587+ line_length ++ ;
1588+ cursor_pos ++ ;
1589+ shell_redraw_line ();
15921590}
0 commit comments