C++ -> C
This commit is contained in:
7
ui/BUILD
7
ui/BUILD
@@ -1,7 +0,0 @@
|
||||
cc_library(
|
||||
name="ui",
|
||||
srcs = ["base.cc"],
|
||||
hdrs = ["base.h"],
|
||||
deps = ["@system_include//:curses"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
18
ui/base.c
Normal file
18
ui/base.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "base.h"
|
||||
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void draw_text(char *text, int *x, int *y) {
|
||||
if (!text || strnlen(text, 1) == 0) return;
|
||||
|
||||
mvaddch(*y, *x, *text);
|
||||
++text;
|
||||
|
||||
for (; *text != '\0'; ++text) {
|
||||
addch(*text);
|
||||
}
|
||||
|
||||
getyx(stdscr, *y, *x);
|
||||
}
|
||||
23
ui/base.cc
23
ui/base.cc
@@ -1,23 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
14
ui/base.h
14
ui/base.h
@@ -1,14 +1,10 @@
|
||||
#ifndef UI_BASE_H_
|
||||
#define UI_BASE_H_
|
||||
|
||||
#include <string>
|
||||
/**
|
||||
* Prints the string text starting at position *x, *y. x and y are updated to
|
||||
* the position after the last character
|
||||
*/
|
||||
void draw_text(char *text, int *x, int *y);
|
||||
|
||||
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_
|
||||
|
||||
Reference in New Issue
Block a user