Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/utils/input_output.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
#include "input_output.hpp"

#include <iostream>

#include "ansi_code.hpp"

// OS-specific libraries.
#include <sys/ioctl.h>

unsigned int cursor_hider::s_scope_count = 0;

cursor_hider::cursor_hider(bool hide /* = true */)
: m_hide(hide)
{
std::cout << (m_hide ? ansi_code::hide_cursor : ansi_code::show_cursor);
s_scope_count++;
write_ansi_code(m_hide);
}

cursor_hider::~cursor_hider()
{
std::cout << (m_hide ? ansi_code::show_cursor : ansi_code::hide_cursor);
s_scope_count--;

if (s_scope_count == 0)
{
// Ensure cursor is visible when git2cpp exits.
write_ansi_code(false);
}
else
{
write_ansi_code(!m_hide);
}
}

void cursor_hider::write_ansi_code(bool hide)
{
std::cout << (hide ? ansi_code::hide_cursor : ansi_code::show_cursor);
}

alternative_buffer::alternative_buffer()
Expand Down
6 changes: 4 additions & 2 deletions src/utils/input_output.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <iostream>

#include "common.hpp"

// OS-specific libraries.
Expand All @@ -22,7 +20,11 @@ class cursor_hider : noncopyable_nonmovable

private:

void write_ansi_code(bool hide);

bool m_hide;

static unsigned int s_scope_count;
};

// Scope object to use alternative output buffer for
Expand Down