Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a RangBuffer class in response to (enhancement) issue #52 #107

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Created a RangBuffer class in response to (enhancement) issue #52 #107

wants to merge 10 commits into from

Conversation

HemilTheRebel
Copy link

@HemilTheRebel HemilTheRebel commented Nov 3, 2018

I created a RangBuffer class to store the display settings in an object. You might want to make a class 'buffer' inside rang namespace. It has setter functions to set the properties. This is how it works:

RangBuffer rg;

rg.setBgColor(rang::bg::cyan);
rg.setFgBColor(rang::fgB::yellow);

cout << rg << "hello world\n" << endl;
rg.ignoreMySettings(cout);

RangBuffer rg2;
rg2.setBgBColor(rang::bgB::blue);
cout << rg2 << "hello world\n";
cout << rg << "This is my first contribution";

There is a unique function RangBuffer::ignoreMysettings(std::ostream& os). It resets the ostream. So for example in the above code, the second line is displayed with a bright blue background and white foreground. Commenting that line will display the second line with a bright blue background and yellow colour (set by rg1).

Now you might be wandering what's the difference between ignoreMySettings and reset()?

  • Reset resets the all the bitset (elementSet) to 0 in addition to resetting the terminal. So, after calling the clear function, it is as good as a new object.
  • IgnoreMySettings resets the terminal but does not reset the bitset. It means the next time the object is used to display using ostream.

Plus, the design choice is such that say you have a common setting that the text you display is red, but at some point, you want red and the text to be bold, you can do this:

RangBuffer rg;
rg.setFgBColor(rang::fgB::red);

cout << rang::style::bold << rg << "Hello world";
rg.reset(cout);

And it does all this without breaking code.

I compiled my example on g++(version 8.2.1) and clang++(version 7.0) both on my Fedora 29. And it works as expected

@HemilTheRebel
Copy link
Author

Can i get the test cases that failed?

@agauniyal
Copy link
Owner

Thanks for the PR, I don't think some test case is failing instead the build process itself is failing. I'll setup the CI once again.

@HemilTheRebel
Copy link
Author

@agauniyal, if I may ask, do you really need a build system and/or CI/CD for a single 500 line header file?

@agauniyal
Copy link
Owner

@HemilTheRebel it does nothing what a typical build system does, it's just there so we can write code just once and CI/CD shows errors on different OS with their different compilers with their different versions.

Nothing else is done 😄

…nce. Made this change because I was converting from stringstream to a string many times. (On Lecraouille's recommendation)
@agauniyal
Copy link
Owner

Have fixed the CI so this should build now..

@agauniyal
Copy link
Owner

@HemilTheRebel the code looks good, from what I can gather it won't do anything on Windows xp/7/8/8.1 versions, right?

@HemilTheRebel
Copy link
Author

I don't have those operating systems. I have Fedora 29 and Windows 10. So, you are a better judge. I don't do anything else. I just make reuse what you have done and save it in a string

@agauniyal
Copy link
Owner

@HemilTheRebel rang aims to work with previous windows versions as well, the current problem I was facing with storing rang information into strings is that it won't work with previous windows versions and I came up with roughly what you've here. The problem is that previous windows versions don't parse ansi escape sequences, rather you've to explicitly call methods onto console that do the right thing, which need some thinking to get stored into a stream/buffer 😄

@HemilTheRebel
Copy link
Author

I didn't know that. I am a newbie and I have never done Windows specific applications. But this is easy. In the output operator, you can check (using macros) the version of windows and if its not win 10, you can parse through the strings and call the appropriate functions. But again, I need help. I don't know 'windows development'

@agauniyal
Copy link
Owner

@HemilTheRebel with current design, it seems that this feature isn't supportable directly. We need to find a way to store strings and rang objects together in single buffer(which can be thought as std::variant<std::string, rang::bg, rang::fg....>) then make another function that can parse that buffer and perform the required actions.

@HemilTheRebel
Copy link
Author

HemilTheRebel commented Dec 9, 2018 via email

@HemilTheRebel HemilTheRebel reopened this Dec 9, 2018
@HemilTheRebel
Copy link
Author

HemilTheRebel commented Dec 16, 2018

I tried a lot. Windows is freaking me out. The amount of windows-specific code that needs to be manipulated is a lot. And I don't know Windows programming.

HemilTheRebel and others added 2 commits December 16, 2018 19:29
…s its private member instead of a string stream. This was done so that rang::buffer can be used on Windows other than 10
…rs. Windows was fine but linux needed that
@codecov
Copy link

codecov bot commented Dec 16, 2018

Codecov Report

Merging #107 into master will decrease coverage by 3.31%.
The diff coverage is 5.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #107      +/-   ##
==========================================
- Coverage    95.6%   92.29%   -3.32%     
==========================================
  Files           4        4              
  Lines         501      519      +18     
==========================================
  Hits          479      479              
- Misses         22       40      +18
Impacted Files Coverage Δ
include/rang.hpp 79.27% <5.26%> (-8.16%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cabe04d...4db7d72. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 16, 2018

Codecov Report

Merging #107 into master will decrease coverage by 3.31%.
The diff coverage is 5.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #107      +/-   ##
==========================================
- Coverage    95.6%   92.29%   -3.32%     
==========================================
  Files           4        4              
  Lines         501      519      +18     
==========================================
  Hits          479      479              
- Misses         22       40      +18
Impacted Files Coverage Δ
include/rang.hpp 79.27% <5.26%> (-8.16%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cabe04d...aefb61d. Read the comment docs.

…ot verify Windows < 10 because i don't have them. But in theory should work).

Added ".vs" to the git-ignore
@HemilTheRebel
Copy link
Author

@agauniyal , have a look at that. I changed the design. I wanted to avoid this but I have no choice. This should (in theory) keep the backwards compatibility. I only have Windows 10 and Fedora 29. So i could only verify on those operating systems. My tests are successful on those platforms. If you have older versions of Windows, would you try them out?

@agauniyal
Copy link
Owner

@HemilTheRebel your approach with vector is good but it only stores rang specific information and not the actual content user wants to print, for eg. rangBuffer << "Hey" << rang::red << "this is a number: " << 4.12;` and the user can use this buffer to print contents later. It contains a string type, rang specific info and even a floating point value. But this is the initial step to think how to store all kinds of values into single stream. You also cannot use templates here because you don't know in advance what types will user be putting into this stream(it works as long as << is defined for them - which again helps you to use templates ;) but think in terms of std::variant to make this easier).

About the changes, they're as generic as possible but I'm afraid they won't cover older windows. They will compile under older windows, for sure, but they won't work as intended.

@HemilTheRebel
Copy link
Author

HemilTheRebel commented Dec 24, 2018

I am really sorry but I have no way to test it on any other platform(s).

About the stream, what I thought about how people would use it is they would store the style of text in a variable and display all the strings they want to look the same way using a single variable. What you want can easily be implemented by making another class having a vector of pair of rang::buffer and a string. We can use the to_string() function to convert other types to string. That way we can ask the user to define their own to_string() function for their own type (if they need).

But I don't understand how to use std::variant in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants