Comments (11)
Awesome, thanks!
from cpp-terminal.
Yeah, it's the usual issue of distributing C++ libraries. For LFortran I simply copy cpp-terminal
into a tpl directory. So splitting into source/header files would not be a problem, I would just add the source file into LFortran's CMake file. So I am fine with that.
@wolfv, @SylvainCorlay what do you think is the best approach here?
from cpp-terminal.
I have looked into it and do you want to merge both terminal_base and terminal into one file? I think it would be better to do two seperate source files with seperate headers. I would even do a seperate header and source file to provide things like widgets and such.
My Idea would be:
- terminal-base.hpp to provide the bare minimum to get you started with controling the terminal (that would include save_screen(), get_corsor_position(), the coloring and functions like that)
- terminal.hpp to provide a class with a developer friendly kind of abstraction that provides a small and simple set of functions which do most of the work in the background so the user don't needs to deal with that (like ncurses does).
- widgets.hpp / utils.hpp / extra.hpp (or however we will call it) for providing widgets to be used with terminal.hpp with things like progress bar, "windows" around text etc.
- optionally we can also provide a small header for optional things that are not associated with terminal but quiet usefull for writing application, I'm thinking about things like a sleep function and things like that
What do you think?
from cpp-terminal.
@certik How do you would like to proceed with the header files?
terminal.cpp
terminal.h <- actual features
terminal_base.cpp
terminal_base.h <- platform dependent code
or
base.cpp
base.h <- colors, styles, print functions etc
extra.cpp
extra.h <- auto color, widgets, shapes etc (also prompt, but could be placed in it's own header file)
input.cpp
input.h <- input stuff
window.cpp
window.h <- window class
platform.h <- plattform specific code to keep the other files clean. Just using a internal header files allows to make all functions inline
from cpp-terminal.
I would go with your second approach.
Regarding the platform dependent stuff, the way to do it is to have platform.h
which contains the API (in one way or another) that by itself is platform independent, and then platform.cpp
contains the implementation which contains #ifdef
for each platform. That way all the platform dependent stuff is in just one file, platform.cpp
, no other file and no header file. So every header file and every other cpp file is platform independent.
from cpp-terminal.
I was thinking about using the platform.h file as "Private" header -> project only. So we can simply create the smallest possible functions in the header file and include it into the source files of our project. The public headers would keep clean as well as the other source files. It would allow us to have the minimum for the platform independence inside of the platform header and keep all the logic and things that might need to be changed for new features in their source files.
Example:
platfrom.hpp
inline void get_term_size(row, col) {
// logic with platform dependence
}
inline int get_input_raw() {
// platform dependent parts
}
base.cpp:
#include "platform.hpp"
void Term::get_term_size(row, col) {
get_term_size(row,col)
}
int get_input() {
// parse get_input_raw for specific terminals
}
I wouldn't chose an approach to make the platform dependent stuff available directly, because those things are parts of others like the whole terminal size and interactive tty functions are part of the base.h
header. Also not making the functions inline creates overhead on MSVC because it's unrolling only some functions while GCC and CLang are unrolling most things starting with -O2 (Have tested that with a friend a few weeks before out of interest). Also I'm not sure if it would bring any difference for coding here.
So what do you say @certik? Making a source file for platform as well or just a header? In the ends it's probably not that big of a deal (also the windows terminal is slow anyway. A hello world compiled with MSVC (and /Ofast) is already over 450 lines of assembly, while linux (gcc, also with -Ofast) needs 20 lines of assembly).
from cpp-terminal.
So what do you say?
from cpp-terminal.
from cpp-terminal.
Either is fine with me. Yes, the header would be private. You can start with just a header and only include it in cpp files. If we need more, we can expand it.
from cpp-terminal.
Ok, I'll make a PR in the coming days. Thanks!
from cpp-terminal.
Fixed in #132.
from cpp-terminal.
Related Issues (20)
- Flickering HOT 20
- Windows terminal can be turned into `legacy mode` and so crash our ANSII support detection
- example 'kilo' does not support special characters HOT 7
- exception leaking destructor is dangerous HOT 10
- build as shared library, error adding symbols: DSO missing from command line HOT 12
- Compiling the examples with GCC results in errors HOT 7
- Create a list of projects that are using this library HOT 3
- Bug: cpp-terminal crashes if two utf8 are inserted simultaneously HOT 42
- Multiline prompt stopped working on macOS
- Ctrl + I and Tab HOT 6
- Bug: Text Wrap Incompatibility HOT 6
- Bring back the list of other similar libraries HOT 4
- Pressing Ctrl, Alt, Shift creates a copy paste event on windows? HOT 3
- Addition of Metakey and Key results in warning of deprecation HOT 1
- Bug in key + metakey arithmetic HOT 7
- Exception thrown at this line when typeing to fast HOT 7
- mouse sending random characters to the terminal after examples/minimal ends HOT 8
- `std::cin` doesn't read pipe redirection HOT 8
- Issue with file headers HOT 3
- Doctest.h needs to be updated to the latest version - compile error on Ubuntu 22.04 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpp-terminal.