~kiwec/ke

ref: 842396976984e3cbd83251296dd90a46b9d53b3c ke/src/StatusBar.cc -rw-r--r-- 1.3 KiB
84239697 — Wolf Clément Downgrade to C++17, avoid stdlib 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "StatusBar.h"
#include "Buffer.h"
#include "Conversion.h"
#include "Editor.h"
#include "File.h"
#include "Line.h"
#include <sstream>
#include <termbox.h>

void StatusBar::draw(Buffer& buf) {
	// Text aligned to the left
	std::wostringstream left;
	// Filename
	auto wfilename = Convert::to_wide_string(buf.filename.c_str());
	left << L" " << wfilename.get();
	left << L" " << buf.force;

	// Modified
	if(buf.modified) {
		left << L" [modified]";
	}
	auto left_str = left.str();

	// Text aligned to the right
	std::wostringstream right;
	right << L" ";
	// Character count
	right << L"Col " << buf.get_visible_x() - 1;
	right << L"/" << buf.current_line().width();
	right << L" | ";

	// Line count
	right << L"Line " << buf.get_current_line_nb();
	right << L"/" << buf.m_text.get_nb_lines();
	right << L" ";
	auto right_str = right.str();
	auto rwidth = right_str.size();

	// Yellow background
	for(int i = 0; i < tb_width(); i++) {
		tb_change_cell(i, tb_height() - 1, ' ', fg, bg);
	}

	// Filename
	Canvas::print(left_str.c_str(), 0, tb_height() - 1, fg, bg);

	// Text
	Canvas::print(right_str.c_str(), tb_width() - rwidth, tb_height() - 1, fg, bg);

	// Prompt
	if(prompt != nullptr) {
		if(prompt->is_prompting()) {
			prompt->draw(rwidth);
		} else {
			prompt = nullptr;
		}
	}
}

int StatusBar::height() {
	// Could be higher in the future
	return 1;
}