Switch to C++

This commit is contained in:
2018-01-07 22:24:23 -08:00
parent efc529bec8
commit 3a10624966
7 changed files with 47 additions and 41 deletions

View File

@@ -1,6 +1,6 @@
cc_library(
name="ui",
srcs = ["base.c"],
srcs = ["base.cc"],
hdrs = ["base.h"],
deps = ["@system_include//:curses"],
visibility = ["//visibility:public"],

View File

@@ -1,17 +0,0 @@
#include "base.h"
#include <curses.h>
#include <string.h>
void draw_text(int *x, int *y, char *text) {
size_t len = strlen(text);
if (!len) return;
mvaddch(*x, *y, text[0]);
for (size_t i=1; i < strlen(text); i++) {
addch(text[i]);
}
getyx(stdscr, *y, *x);
}

23
ui/base.cc Normal file
View File

@@ -0,0 +1,23 @@
#include "base.h"
#include <curses.h>
#include <string.h>
#include <string>
namespace ui {
void draw_text(const std::string text, int *x, int *y) {
if (!text.length()) return;
auto iter = text.begin();
mvaddch(*y, *x, *iter);
++iter;
for (; iter != text.end(); ++iter) {
addch(*iter);
}
getyx(stdscr, *y, *x);
}
}

View File

@@ -1,10 +1,14 @@
#ifndef UI_BASE_H_
#define UI_BASE_H_
/**
* Prints the string text starting at position *x, *y. x and y are updated to
* the position after the last character
*/
void draw_text(int *x, int *y, char *text);
#include <string>
namespace ui {
/**
* Prints the string text starting at position *x, *y. x and y are updated to
* the position after the last character
*/
void draw_text(const std::string text, int *x, int *y);
} // namespace ui
#endif // UI_BASE_H_