Skip to content

Instantly share code, notes, and snippets.

View njlr's full-sized avatar
🌏
F# ing

njlr njlr

🌏
F# ing
View GitHub Profile
counting from 1 to 10: i=1 [#_________]
counting from 1 to 10: i=2 [##________]
counting from 1 to 10: i=3 [###_______]
counting from 1 to 10: i=4 [####______]
counting from 1 to 10: i=5 [#####_____]
unsigned const terminalWidth = 80;
int main() {
VirtualTerminal vt;
auto const fancyCounter = [](auto start, auto end, auto i) -> FlowLayout<> {
  return {
  Text("counting from "), Text({ Font::Bold }, start), 
  Text(" to "), Text({ Font::Bold }, end),
  Text(": i="), Text({ FgColor::Red, Font::Underline }, i) 
#include <iostream>
int main() {
 std::cout << "\e[31m" << "Hello" << "\e[0m" << World" << std::endl;
 return 0;
}
enum class Color { /* ... */ };
enum class Font { /* ... */ };
struct Style {
 Color bg;
  Color fg;
  Font font;
};
struct Pixel {
struct Renderable {
 virtual Image render(unsigned const width) const = 0;
  virtual ~Renderable() {}
};
template<class T>
struct Model : Renderable {
  T data;
struct Text {
 Style style; 
  std::string text;
  Image render() const {
  std::vector<Pixel> pixels(text.size(), Pixel{ style });
  for (int i = 0; i < text.size(); ++i) {
  pixels[i].c = text[i]; 
  }
  return Image{ width, height, pixels };
running task: download
progress(50%): [xxxxxx ]
Tasks Done: 1/5: [x ]
running task: download
progress(75%): [xxxxxxxxx ]
Tasks Done: 1/5: [x ]
// Pseudo-code
struct VirtualTerminal {
 string buffer; // Currently visible output
 
 string computeTransition(string const& prev, string const& next) {
  const string deleteLine = "\e[2K\r\e[1A";
  return repeat(count("\n", prev), deleteLine()) + next;
  }
 
  VirtualTerminal flip(std::string const& str) const {
@njlr
njlr / f.java
Created September 7, 2017 10:35
int f() {
 Foo foo = new Foo();
  return foo.bar();
}