Giter Site home page Giter Site logo

Comments (11)

certik avatar certik commented on May 23, 2024 1

Awesome, thanks!

from cpp-terminal.

certik avatar certik commented on May 23, 2024

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.

MCWertGaming avatar MCWertGaming commented on May 23, 2024

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.

MCWertGaming avatar MCWertGaming commented on May 23, 2024

@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.

certik avatar certik commented on May 23, 2024

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.

MCWertGaming avatar MCWertGaming commented on May 23, 2024

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.

MCWertGaming avatar MCWertGaming commented on May 23, 2024

So what do you say?

from cpp-terminal.

MCWertGaming avatar MCWertGaming commented on May 23, 2024

@certik

from cpp-terminal.

certik avatar certik commented on May 23, 2024

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.

MCWertGaming avatar MCWertGaming commented on May 23, 2024

Ok, I'll make a PR in the coming days. Thanks!

from cpp-terminal.

MCWertGaming avatar MCWertGaming commented on May 23, 2024

Fixed in #132.

from cpp-terminal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.