Skip to content

Commit 5c4b5ba

Browse files
committed
Fix
1 parent afcc7ce commit 5c4b5ba

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

cpp-terminal/cursor.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ void Term::Cursor::setRow(const std::size_t& row) { m_position.first = row; }
2121

2222
void Term::Cursor::setColum(const std::size_t& column) { m_position.second = column; }
2323

24-
Term::Cursor Term::cursor_position()
25-
{
26-
// write cursor position report
27-
std::cout << cursor_position_report() << std::flush;
28-
Term::Event c;
29-
while((c = Platform::read_raw()).empty()) continue;
30-
return c;
31-
}
32-
3324
std::string Term::cursor_off() { return "\x1b[?25l"; }
3425

3526
std::string Term::cursor_on() { return "\x1b[?25h"; }
@@ -44,6 +35,6 @@ std::string Term::cursor_right(std::size_t columns) { return "\033[" + std::to_s
4435

4536
std::string Term::cursor_left(std::size_t columns) { return "\033[" + std::to_string(columns) + 'D'; }
4637

47-
std::string Term::cursor_position_report() { return "\x1b[6n"; }
38+
std::string Term::cursor_position_report() { return "\033[6n"; }
4839

4940
std::string Term::clear_eol() { return "\033[K"; }

cpp-terminal/event.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "cpp-terminal/cursor.hpp"
44

5+
#include <iostream>
6+
57
bool Term::Event::empty()
68
{
79
if(m_Type == Type::Empty) return true;
@@ -33,6 +35,7 @@ Term::Event::Event(const std::string& str) : m_Type(Type::CopyPaste), m_str(str)
3335

3436
void Term::Event::parse()
3537
{
38+
std::cout<<"LL "<<m_str<<std::endl;
3639
if(m_str.size() == 1)
3740
{
3841
m_Type = Type::Key;
@@ -53,6 +56,7 @@ void Term::Event::parse()
5356
if(found != std::string::npos)
5457
{
5558
m_Type = Type::Cursor;
59+
5660
m_Cursor = Cursor(std::stoi(m_str.substr(2, found - 2)), std::stoi(m_str.substr(found + 1, m_str.size() - (found + 2))));
5761
}
5862
}

cpp-terminal/platforms/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_library(cpp-terminal-platforms terminal.cpp tty.cpp terminfo.cpp input.cpp screen.cpp)
1+
add_library(cpp-terminal-platforms terminal.cpp tty.cpp terminfo.cpp input.cpp screen.cpp cursor.cpp)
22
target_link_libraries(cpp-terminal-platforms PRIVATE Warnings::Warnings)
33
target_compile_options(cpp-terminal-platforms PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>)
44
target_include_directories(cpp-terminal-platforms PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> $<INSTALL_INTERFACE:include>)

cpp-terminal/platforms/cursor.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "cpp-terminal/cursor.hpp"
2+
3+
#if defined(_WIN32)
4+
#include "windows.h"
5+
#else
6+
#include "cpp-terminal/event.hpp"
7+
#include "cpp-terminal/input.hpp"
8+
#include <iostream>
9+
#endif
10+
11+
Term::Cursor Term::cursor_position()
12+
{
13+
#if defined(_WIN32)
14+
Term::Cursor ret;
15+
HANDLE hConOut{CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)};
16+
CONSOLE_SCREEN_BUFFER_INFO inf;
17+
if(GetConsoleScreenBufferInfo(hConOut, &inf)) { ret = {static_cast<std::size_t>(inf.dwCursorPosition.Y+1), static_cast<std::size_t>(inf.dwCursorPosition.X+1)}; }
18+
CloseHandle(hConOut);
19+
return ret;
20+
#else
21+
std::cout << Term::cursor_position_report() << std::flush;
22+
Term::Event c;
23+
while((c = Platform::read_raw()).empty());
24+
return c;
25+
#endif
26+
}

cpp-terminal/platforms/screen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Term::Screen Term::screen_size()
1414
Term::Screen ret;
1515
HANDLE hConOut{CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)};
1616
CONSOLE_SCREEN_BUFFER_INFO inf;
17-
if(GetConsoleScreenBufferInfo(hConOut, &inf)) { ret = {inf.srWindow.Bottom - inf.srWindow.Top + 1, inf.srWindow.Right - inf.srWindow.Left + 1}; }
17+
if(GetConsoleScreenBufferInfo(hConOut, &inf)) { ret = {static_cast<std::size_t>(inf.srWindow.Bottom - inf.srWindow.Top + 1), static_cast<std::size_t>(inf.srWindow.Right - inf.srWindow.Left + 1)}; }
1818
CloseHandle(hConOut);
1919
return ret;
2020
#else

0 commit comments

Comments
 (0)