Skip to content

Commit 3b96748

Browse files
committed
Add minimal examples to README.md
1 parent f498906 commit 3b96748

File tree

3 files changed

+76
-11
lines changed

3 files changed

+76
-11
lines changed

README.md

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,66 @@
99
[![pre-commit](https://github.com/jupyter-xeus/cpp-terminal/actions/workflows/pre-commit-check.yml/badge.svg)](https://github.com/jupyter-xeus/cpp-terminal/actions/workflows/pre-commit-check.yml)
1010
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/jupyter-xeus/cpp-terminal/master.svg)](https://results.pre-commit.ci/latest/github/jupyter-xeus/cpp-terminal/maset)
1111

12-
`CPP-Terminal` is a small and simple library for writing platform independent terminal applications. It works on Windows, MacOS and Linux and offers a simple programming interface. It
13-
supports colors, keyboard input and has all the basic features to write any
14-
terminal application.
12+
`CPP-Terminal` is a small and simple library for writing platform independent terminal applications. It tries to follow the C++ 'Zero-overhead principle' and its headers only include C++ ones. It works on Windows, MacOS and Linux and offers a simple
13+
programming interface. It
14+
supports colors, keyboard input and has all the basic features to write any terminal application. On windows the library automatically allocate a console on GUI application and set up cin, cout, cerr etc...
15+
16+
## Minimal example
17+
18+
The minimal Hello World is as simple as :
19+
20+
```cpp
21+
#include "cpp-terminal/io.hpp"
22+
23+
#include <iostream>
24+
25+
int main()
26+
{
27+
std::cout << "\033[31mHello world !\033[0m" << std::endl;
28+
return 0;
29+
}
30+
```
31+
32+
or
33+
34+
```cpp
35+
#include "cpp-terminal/io.hpp"
36+
#include "cpp-terminal/color.hpp"
37+
38+
#include <iostream>
39+
40+
int main()
41+
{
42+
std::cout << Term::color_fg(Term::Color::Name::Red)<<"Hello world !"<<color_fg(Term::Color::Name::Default)<< std::endl;
43+
return 0;
44+
}
45+
```
46+
47+
On windows, creating a console or attaching console to a GUI application can be done easily :
48+
49+
```cpp
50+
#include "cpp-terminal/io.hpp"
51+
#include "cpp-terminal/color.hpp"
52+
53+
#include <iostream>
54+
55+
int __stdcall WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int show)
56+
{
57+
std::cout << Term::color_fg(Term::Color::Name::Red)<<"Hello world !"<<color_fg(Term::Color::Name::Default)<< std::endl;
58+
return 0;
59+
}
60+
```
1561
1662
Until 2021, CPP-Terminal used to be a single header library. Now, CPP-Terminal consists out of multiple small and usage oriented headers:
63+
1764
- `cpp-terminal/base.hpp`: everything for basic Terminal control
1865
- `cpp-terminal/input.hpp`: functions for gathering input
1966
- `cpp-terminal/prompt.hpp`: some variations of different prompts
2067
- `cpp-terminal/window.hpp`: a fully managed terminal window for terminal user interfaces (TUI)
2168
- `cpp-terminal/version.hpp`: macros with cpp-terminal's version number
2269
2370
The library uses private header for platform dependent code:
71+
2472
- `cpp-terminal/private/conversion.hpp`: Various conversions
2573
- `cpp-terminal/private/platform.hpp`: platform dependent code
2674
@@ -38,14 +86,14 @@ We have created serval examples to show possible use cases of CPP-Terminal and t
3886
3987
## Supported platforms
4088
41-
| Platform | Supported versions | Coverage by unit test |
42-
|-------------------|--------------------|-----------------------|
43-
| Windows | 10 and higher* | MSVC |
44-
| (Windows) MSYS2 | All supported | / |
45-
| (Windows) Cygwin | All supported | / |
46-
| (Windows) MinGW | All supoorted | / |
47-
| MacOS | All supported | Apple-clang |
48-
| Linux | All supported | GCC>= 5 Clang >= 3.6 |
89+
| Platform | Supported versions | Arch | Compiler | C++ standard |
90+
|:-----------------:|:------------------:|:----------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------:|:------------:|
91+
| Windows | 10 and higher* | x86, x86_64 | MSVC 2019, MSVC 2022, clang11, clang12, clang13, clang14, clang15, clang-cl | 11,14,17,20 |
92+
| (Windows) MSYS2 | All supported | x86, x86_64 | ucrt , clang, mingw | 11,14,17,20 |
93+
| MacOS | 11 | | xcode11.7 xcode12.4 xcode12.5.1 xcode13 gcc10 gcc11 gcc12 | 11,14,17,20 |
94+
| MacOS | 12 | | xcode13.1 xcode13.2 xcode13.3 xcode13.4 | 11,14,17,20 |
95+
| Linux | All supported | x86_64 | 4.7<=GCC<= 12 3.5<=Clang<=15 intel-oneapi | 11,14,17,20 |
96+
| Linux (dockcross) | All supported | arm64 armv5 armv5-musl armv5-uclibc armv6 armv7a, mips, mipsel-lts, s390x, ppc64le, xtensa-uclibc, x86, x64, x64-clang, x64-tinycc | 4.7<=GCC<= 12 3.5<=Clang<=15 | 11,14,17,20 |
4997
5098
> Windows versions prior Windows 10 are missing the Win32 API functionality for entering the "raw mode" and therefore won't work. They are also lacking ANSI support. See #173 for adding support to prior windows versions for MSVC / Win32.
5199

tests/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ doctest_discover_tests(test_terminal)
2929
add_executable(AttachConsole WIN32 attach_console.test.cpp)
3030
target_link_libraries(AttachConsole PRIVATE doctest::doctest cpp-terminal::cpp-terminal)
3131

32+
add_executable(AttachConsoleMinimal WIN32 attach_console_minimal.test.cpp)
33+
target_link_libraries(AttachConsoleMinimal PRIVATE doctest::doctest cpp-terminal::cpp-terminal)
34+
3235
if(WIN32)
3336
find_program(POWERSHELL_EXECUTABLE NAMES powershell DOC "PowerShell command")
3437
if(NOT ${POWERSHELL_EXECUTABLE} STREQUAL "POWERSHELL_EXECUTABLE-NOTFOUND")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "cpp-terminal/color.hpp"
2+
#include "cpp-terminal/io.hpp"
3+
4+
#include <iostream>
5+
6+
#ifdef _WIN32
7+
int __stdcall WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int show)
8+
#else
9+
int main()
10+
#endif
11+
{
12+
std::cout << Term::color_fg(Term::Color::Name::Red) << "Hello world !" << color_fg(Term::Color::Name::Default) << std::endl;
13+
return 0;
14+
}

0 commit comments

Comments
 (0)