Added support for switching the terminal to bold mode.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
#include "native.h"
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <curses.h>
|
||||
#include <term.h>
|
||||
|
||||
void markFailed(JNIEnv *env, jobject result) {
|
||||
jclass destClass = env->GetObjectClass(result);
|
||||
@@ -11,6 +14,19 @@ void markFailed(JNIEnv *env, jobject result) {
|
||||
env->CallVoidMethod(result, method, errno);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic functions
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_net_rubygrapefruit_platform_internal_NativeLibraryFunctions_getVersion(JNIEnv *env, jclass target) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* File functions
|
||||
*/
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_net_rubygrapefruit_platform_internal_PosixFileFunctions_chmod(JNIEnv *env, jclass target, jstring path, jint mode, jobject result) {
|
||||
const char* pathUtf8 = env->GetStringUTFChars(path, NULL);
|
||||
@@ -34,11 +50,19 @@ Java_net_rubygrapefruit_platform_internal_PosixFileFunctions_stat(JNIEnv *env, j
|
||||
env->SetIntField(dest, modeField, 0777 & fileInfo.st_mode);
|
||||
}
|
||||
|
||||
/*
|
||||
* Process functions
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_net_rubygrapefruit_platform_internal_PosixProcessFunctions_getPid(JNIEnv *env, jclass target) {
|
||||
return getpid();
|
||||
}
|
||||
|
||||
/*
|
||||
* Terminal functions
|
||||
*/
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_net_rubygrapefruit_platform_internal_PosixTerminalFunctions_isatty(JNIEnv *env, jclass target, jint output) {
|
||||
switch (output) {
|
||||
@@ -64,3 +88,51 @@ Java_net_rubygrapefruit_platform_internal_PosixTerminalFunctions_getTerminalSize
|
||||
jfieldID heightField = env->GetFieldID(dimensionClass, "rows", "I");
|
||||
env->SetIntField(dimension, heightField, screen_size.ws_row);
|
||||
}
|
||||
|
||||
/*
|
||||
* Terminfo functions
|
||||
*/
|
||||
|
||||
int current_terminal = -1;
|
||||
|
||||
int write_to_terminal(int ch) {
|
||||
write(current_terminal, &ch, 1);
|
||||
}
|
||||
|
||||
void write_capability(JNIEnv *env, const char* capability, jobject result) {
|
||||
char* cap = tgetstr((char*)capability, NULL);
|
||||
if (cap == NULL) {
|
||||
markFailed(env, result);
|
||||
return;
|
||||
}
|
||||
if (tputs(cap, 1, write_to_terminal) == ERR) {
|
||||
markFailed(env, result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_net_rubygrapefruit_platform_internal_TerminfoFunctions_initTerminal(JNIEnv *env, jclass target, jint output, jobject result) {
|
||||
char* termType = getenv("TERM");
|
||||
if (termType == NULL) {
|
||||
markFailed(env, result);
|
||||
return;
|
||||
}
|
||||
int retval = tgetent(NULL, termType);
|
||||
if (retval != 1) {
|
||||
markFailed(env, result);
|
||||
return;
|
||||
}
|
||||
current_terminal = output + 1;
|
||||
write_capability(env, "me", result);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_net_rubygrapefruit_platform_internal_TerminfoFunctions_bold(JNIEnv *env, jclass target, jint output, jobject result) {
|
||||
write_capability(env, "md", result);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_net_rubygrapefruit_platform_internal_TerminfoFunctions_normal(JNIEnv *env, jclass target, jint output, jobject result) {
|
||||
write_capability(env, "me", result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user