Skip to content

Commit

Permalink
Merge pull request #168 from KazDragon/terminal-manip#139
Browse files Browse the repository at this point in the history
Terminal manip#139
  • Loading branch information
KazDragon authored Aug 21, 2017
2 parents b3abf8d + 46bc796 commit 9852d6d
Show file tree
Hide file tree
Showing 18 changed files with 647 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ set(TERMINALPP_SOURCE_FILES
src/detail/parser.cpp
src/detail/well_known_virtual_key.cpp
src/ansi_terminal.cpp
src/manip/terminal_streamer.cpp
)

set(TERMINALPP_INCLUDE_FILES
Expand All @@ -155,6 +156,21 @@ set(TERMINALPP_INCLUDE_FILES
include/terminalpp/detail/terminal_cursor_control.hpp
include/terminalpp/detail/well_known_virtual_key.hpp
include/terminalpp/ansi_terminal.hpp
include/terminalpp/terminal_manip.hpp
include/terminalpp/manip/disable_mouse.hpp
include/terminalpp/manip/enable_mouse.hpp
include/terminalpp/manip/erase_in_display.hpp
include/terminalpp/manip/erase_in_line.hpp
include/terminalpp/manip/hide_cursor.hpp
include/terminalpp/manip/move_cursor.hpp
include/terminalpp/manip/restore_cursor.hpp
include/terminalpp/manip/save_cursor.hpp
include/terminalpp/manip/set_window_title.hpp
include/terminalpp/manip/show_cursor.hpp
include/terminalpp/manip/terminal_streamer.hpp
include/terminalpp/manip/use_alternate_screen_buffer.hpp
include/terminalpp/manip/use_normal_screen_buffer.hpp
include/terminalpp/manip/write_string.hpp
)

add_library(terminalpp
Expand Down Expand Up @@ -259,6 +275,7 @@ if (GTEST_FOUND)
test/expect_tokens.cpp
test/extent_test.cpp
test/glyph_test.cpp
test/manip_test.cpp
test/point_test.cpp
test/screen_test.cpp
test/string_test.cpp
Expand Down
20 changes: 20 additions & 0 deletions include/terminalpp/manip/disable_mouse.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates mouse disable operation
//* =========================================================================
struct disable_mouse
{
//* =====================================================================
/// \brief Disables the mouse in the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.disable_mouse();
}
};

}
20 changes: 20 additions & 0 deletions include/terminalpp/manip/enable_mouse.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates mouse enable operation
//* =========================================================================
struct enable_mouse
{
//* =====================================================================
/// \brief Enables the mouse in the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.enable_mouse();
}
};

}
30 changes: 30 additions & 0 deletions include/terminalpp/manip/erase_in_display.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates an erase in display operation
//* =========================================================================
struct erase_in_display
{
//* =====================================================================
/// \brief Constructor
//* =====================================================================
constexpr explicit erase_in_display(terminal::erase_display how)
: how_(how)
{
}

//* =====================================================================
/// \brief Erases some of the display of the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.erase_in_display(how_);
}

terminal::erase_display how_;
};

}
30 changes: 30 additions & 0 deletions include/terminalpp/manip/erase_in_line.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates an erase in line operation
//* =========================================================================
struct erase_in_line
{
//* =====================================================================
/// \brief Constructor
//* =====================================================================
constexpr explicit erase_in_line(terminal::erase_line how)
: how_(how)
{
}

//* =====================================================================
/// \brief Erases some of the line in the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.erase_in_line(how_);
}

terminal::erase_line how_;
};

}
20 changes: 20 additions & 0 deletions include/terminalpp/manip/hide_cursor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates a cursor hide operation
//* =========================================================================
struct hide_cursor
{
//* =====================================================================
/// \brief Hides the cursor in the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.hide_cursor();
}
};

}
30 changes: 30 additions & 0 deletions include/terminalpp/manip/move_cursor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates a cursor move operation
//* =========================================================================
struct move_cursor
{
//* =====================================================================
/// \brief Constructor
//* =====================================================================
constexpr explicit move_cursor(terminalpp::point position)
: position_(position)
{
}

//* =====================================================================
/// \brief Moves the cursor in the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.move_cursor(position_);
}

terminalpp::point position_;
};

}
20 changes: 20 additions & 0 deletions include/terminalpp/manip/restore_cursor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates a cursor restore operation
//* =========================================================================
struct restore_cursor
{
//* =====================================================================
/// \brief Restores the cursor in the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.restore_cursor();
}
};

}
20 changes: 20 additions & 0 deletions include/terminalpp/manip/save_cursor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates a cursor save operation
//* =========================================================================
struct save_cursor
{
//* =====================================================================
/// \brief Saves the cursor in the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.save_cursor();
}
};

}
30 changes: 30 additions & 0 deletions include/terminalpp/manip/set_window_title.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates a set window title operation
//* =========================================================================
struct set_window_title
{
//* =====================================================================
/// \brief Constructor
//* =====================================================================
explicit set_window_title(std::string const &title)
: title_(title)
{
}

//* =====================================================================
/// \brief Sets the window title in the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.set_window_title(title_);
}

std::string const &title_;
};

}
20 changes: 20 additions & 0 deletions include/terminalpp/manip/show_cursor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates a cursor show operation
//* =========================================================================
struct show_cursor
{
//* =====================================================================
/// \brief Shows the cursor in the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.show_cursor();
}
};

}
59 changes: 59 additions & 0 deletions include/terminalpp/manip/terminal_streamer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once
#include "terminalpp/core.hpp"
#include <string>

namespace terminalpp {

class terminal;
class string;

//* =========================================================================
/// \brief A class that encapsulates commands being streamed to a terminal.
//* =========================================================================
class terminal_streamer
{
public :
//* =====================================================================
/// \brief Constructor
//* =====================================================================
explicit terminal_streamer(terminal &term)
: terminal_(term)
{
}

//* =====================================================================
/// \brief Converts the result of the streaming operation to a string.
//* =====================================================================
operator std::string() const
{
return result_;
}

//* =====================================================================
/// \brief Streams an operation into the streamer.
//* =====================================================================
template <class Op>
terminal_streamer &operator<<(Op &&op)
{
result_ += op(terminal_);
return *this;
}

//* =====================================================================
/// \brief Streams a string into the streamer.
//* =====================================================================
TERMINALPP_EXPORT
terminal_streamer &operator<<(string const &text);

//* =====================================================================
/// \brief Streams a string into the streamer.
//* =====================================================================
TERMINALPP_EXPORT
terminal_streamer &operator<<(string &&text);

private :
terminal &terminal_;
std::string result_;
};

}
21 changes: 21 additions & 0 deletions include/terminalpp/manip/use_alternate_screen_buffer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates a use alternate screen buffer
/// operation.
//* =========================================================================
struct use_alternate_screen_buffer
{
//* =====================================================================
/// \brief Uses the alternate screen buffer in the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.use_alternate_screen_buffer();
}
};

}
20 changes: 20 additions & 0 deletions include/terminalpp/manip/use_normal_screen_buffer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "terminalpp/terminal.hpp"

namespace terminalpp {

//* =========================================================================
/// \brief A structure that encapsulates a use normal screen buffer operation
//* =========================================================================
struct use_normal_screen_buffer
{
//* =====================================================================
/// \brief Uses the normal screen buffer in the terminal.
//* =====================================================================
std::string operator()(terminal &term)
{
return term.use_normal_screen_buffer();
}
};

}
Loading

0 comments on commit 9852d6d

Please sign in to comment.