Small cleanups in terminal ui
This commit is contained in:
parent
44deaeb4eb
commit
76e5d11c8b
|
@ -18,19 +18,12 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
constexpr char control(char c) { return c & 037; }
|
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
using std::min;
|
using std::min;
|
||||||
using std::max;
|
using std::max;
|
||||||
|
|
||||||
static void set_cursor_pos(DisplayCoord coord)
|
|
||||||
{
|
|
||||||
printf("\033[%d;%dH", (int)coord.line + 1, (int)coord.column + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalUI::Window::create(const DisplayCoord& p, const DisplayCoord& s)
|
void TerminalUI::Window::create(const DisplayCoord& p, const DisplayCoord& s)
|
||||||
{
|
{
|
||||||
pos = p;
|
pos = p;
|
||||||
|
@ -160,7 +153,7 @@ void TerminalUI::Window::blit(Window& target)
|
||||||
|
|
||||||
void TerminalUI::Window::draw(DisplayCoord pos,
|
void TerminalUI::Window::draw(DisplayCoord pos,
|
||||||
ConstArrayView<DisplayAtom> atoms,
|
ConstArrayView<DisplayAtom> atoms,
|
||||||
const Face& default_face)
|
const Face& default_face)
|
||||||
{
|
{
|
||||||
if (pos.line >= lines.size()) // We might receive an out of date draw command after a resize
|
if (pos.line >= lines.size()) // We might receive an out of date draw command after a resize
|
||||||
return;
|
return;
|
||||||
|
@ -456,6 +449,10 @@ void TerminalUI::redraw(bool force)
|
||||||
m_info.blit(m_screen);
|
m_info.blit(m_screen);
|
||||||
|
|
||||||
m_screen.output(force);
|
m_screen.output(force);
|
||||||
|
|
||||||
|
auto set_cursor_pos = [](DisplayCoord c) {
|
||||||
|
printf("\033[%d;%dH", (int)c.line + 1, (int)c.column + 1);
|
||||||
|
};
|
||||||
if (m_cursor.mode == CursorMode::Prompt)
|
if (m_cursor.mode == CursorMode::Prompt)
|
||||||
set_cursor_pos({m_status_on_top ? 0 : m_dimensions.line, m_cursor.coord.column});
|
set_cursor_pos({m_status_on_top ? 0 : m_dimensions.line, m_cursor.coord.column});
|
||||||
else
|
else
|
||||||
|
@ -479,8 +476,8 @@ void TerminalUI::refresh(bool force)
|
||||||
static const DisplayLine empty_line = { String(" "), {} };
|
static const DisplayLine empty_line = { String(" "), {} };
|
||||||
|
|
||||||
void TerminalUI::draw(const DisplayBuffer& display_buffer,
|
void TerminalUI::draw(const DisplayBuffer& display_buffer,
|
||||||
const Face& default_face,
|
const Face& default_face,
|
||||||
const Face& padding_face)
|
const Face& padding_face)
|
||||||
{
|
{
|
||||||
check_resize();
|
check_resize();
|
||||||
|
|
||||||
|
@ -501,8 +498,8 @@ void TerminalUI::draw(const DisplayBuffer& display_buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalUI::draw_status(const DisplayLine& status_line,
|
void TerminalUI::draw_status(const DisplayLine& status_line,
|
||||||
const DisplayLine& mode_line,
|
const DisplayLine& mode_line,
|
||||||
const Face& default_face)
|
const Face& default_face)
|
||||||
{
|
{
|
||||||
const LineCount status_line_pos = m_status_on_top ? 0 : m_dimensions.line;
|
const LineCount status_line_pos = m_status_on_top ? 0 : m_dimensions.line;
|
||||||
m_window.draw(status_line_pos, status_line.atoms(), default_face);
|
m_window.draw(status_line_pos, status_line.atoms(), default_face);
|
||||||
|
@ -625,13 +622,14 @@ Optional<Key> TerminalUI::get_next_key()
|
||||||
if (not c)
|
if (not c)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const cc_t erase = m_original_termios.c_cc[VERASE];
|
static constexpr auto control = [](char c) { return c & 037; };
|
||||||
auto convert = [erase](Codepoint c) -> Codepoint {
|
|
||||||
|
auto convert = [this](Codepoint c) -> Codepoint {
|
||||||
if (c == control('m') or c == control('j'))
|
if (c == control('m') or c == control('j'))
|
||||||
return Key::Return;
|
return Key::Return;
|
||||||
if (c == control('i'))
|
if (c == control('i'))
|
||||||
return Key::Tab;
|
return Key::Tab;
|
||||||
if (c == erase)
|
if (c == m_original_termios.c_cc[VERASE])
|
||||||
return Key::Backspace;
|
return Key::Backspace;
|
||||||
if (c == 127) // when it's not backspace
|
if (c == 127) // when it's not backspace
|
||||||
return Key::Delete;
|
return Key::Delete;
|
||||||
|
@ -953,8 +951,8 @@ static LineCount height_limit(MenuStyle style)
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalUI::menu_show(ConstArrayView<DisplayLine> items,
|
void TerminalUI::menu_show(ConstArrayView<DisplayLine> items,
|
||||||
DisplayCoord anchor, Face fg, Face bg,
|
DisplayCoord anchor, Face fg, Face bg,
|
||||||
MenuStyle style)
|
MenuStyle style)
|
||||||
{
|
{
|
||||||
if (m_menu)
|
if (m_menu)
|
||||||
{
|
{
|
||||||
|
@ -1153,7 +1151,7 @@ static DisplayLineList wrap_lines(const DisplayLineList& lines, ColumnCount max_
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalUI::info_show(const DisplayLine& title, const DisplayLineList& content,
|
void TerminalUI::info_show(const DisplayLine& title, const DisplayLineList& content,
|
||||||
DisplayCoord anchor, Face face, InfoStyle style)
|
DisplayCoord anchor, Face face, InfoStyle style)
|
||||||
{
|
{
|
||||||
info_hide();
|
info_hide();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user