my first commit: makes it possible to load R5 terminal setting files via the command line (Option -p)
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8865 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
#include <UTF8.h>
|
#include <UTF8.h>
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
M_UTF8, /* UTF-8 */
|
||||||
M_ISO_8859_1, /* ISO-8859 */
|
M_ISO_8859_1, /* ISO-8859 */
|
||||||
M_ISO_8859_2,
|
M_ISO_8859_2,
|
||||||
M_ISO_8859_3,
|
M_ISO_8859_3,
|
||||||
@@ -50,7 +51,7 @@ enum {
|
|||||||
M_ISO_2022_JP,
|
M_ISO_2022_JP,
|
||||||
M_SJIS, /* Japanese */
|
M_SJIS, /* Japanese */
|
||||||
M_EUC_JP,
|
M_EUC_JP,
|
||||||
M_EUC_KR,
|
M_EUC_KR
|
||||||
|
|
||||||
// M_EUC_TW, /* Chinese */
|
// M_EUC_TW, /* Chinese */
|
||||||
// M_BIG5,
|
// M_BIG5,
|
||||||
@@ -59,10 +60,10 @@ enum {
|
|||||||
// M_EUC_KR, /* Koeran */
|
// M_EUC_KR, /* Koeran */
|
||||||
// M_ISO_2022_KR,
|
// M_ISO_2022_KR,
|
||||||
|
|
||||||
M_UTF8 /* UTF-8 */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint32 coding_translation_table[] = {
|
const uint32 coding_translation_table[] = {
|
||||||
|
0,
|
||||||
B_ISO1_CONVERSION, /* ISO 8859-1 */
|
B_ISO1_CONVERSION, /* ISO 8859-1 */
|
||||||
B_ISO2_CONVERSION, /* ISO 8859-2 */
|
B_ISO2_CONVERSION, /* ISO 8859-2 */
|
||||||
B_ISO3_CONVERSION, /* ISO 8859-3 */
|
B_ISO3_CONVERSION, /* ISO 8859-3 */
|
||||||
@@ -93,6 +94,7 @@ struct etable
|
|||||||
*/
|
*/
|
||||||
const etable encoding_table[]=
|
const etable encoding_table[]=
|
||||||
{
|
{
|
||||||
|
{"UTF-8", "UTF8", 'U', M_UTF8},
|
||||||
{"ISO-8859-1", "8859-1", '1', M_ISO_8859_1},
|
{"ISO-8859-1", "8859-1", '1', M_ISO_8859_1},
|
||||||
{"ISO-8859-2", "8859-2", '2', M_ISO_8859_2},
|
{"ISO-8859-2", "8859-2", '2', M_ISO_8859_2},
|
||||||
{"ISO-8859-3", "8859-3", '3', M_ISO_8859_3},
|
{"ISO-8859-3", "8859-3", '3', M_ISO_8859_3},
|
||||||
@@ -108,7 +110,6 @@ const etable encoding_table[]=
|
|||||||
{"Shift-JIS", "SJIS", 'S', M_SJIS},
|
{"Shift-JIS", "SJIS", 'S', M_SJIS},
|
||||||
{"EUC-jp", "EUCJ", 'E', M_EUC_JP},
|
{"EUC-jp", "EUCJ", 'E', M_EUC_JP},
|
||||||
{"EUC-kr", "EUCK", 'K', M_EUC_KR},
|
{"EUC-kr", "EUCK", 'K', M_EUC_KR},
|
||||||
{"UTF-8", "UTF8", 'U', M_UTF8},
|
|
||||||
|
|
||||||
/* Not Implement.
|
/* Not Implement.
|
||||||
{"EUC-tw", "EUCT", "T", M_EUC_TW},
|
{"EUC-tw", "EUCT", "T", M_EUC_TW},
|
||||||
|
|||||||
@@ -38,7 +38,48 @@
|
|||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <NodeInfo.h>
|
#include <NodeInfo.h>
|
||||||
|
|
||||||
|
#include "Coding.h"
|
||||||
#include "PrefHandler.h"
|
#include "PrefHandler.h"
|
||||||
|
#include "TermConst.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Startup preference settings.
|
||||||
|
*/
|
||||||
|
const prefDefaults termDefaults[] ={
|
||||||
|
{ PREF_COLS, "80" },
|
||||||
|
{ PREF_ROWS, "25" },
|
||||||
|
|
||||||
|
{ PREF_HALF_FONT_FAMILY, "Courier10 BT" },
|
||||||
|
{ PREF_HALF_FONT_SIZE, "12" },
|
||||||
|
{ PREF_FULL_FONT_FAMILY, "Haru Tohaba" },
|
||||||
|
{ PREF_FULL_FONT_SIZE, "12" },
|
||||||
|
|
||||||
|
{ PREF_TEXT_FORE_COLOR, " 0, 0, 0" },
|
||||||
|
{ PREF_TEXT_BACK_COLOR, "255, 255, 255" },
|
||||||
|
{ PREF_SELECT_FORE_COLOR, "255, 255, 255" },
|
||||||
|
{ PREF_SELECT_BACK_COLOR, " 0, 0, 0" },
|
||||||
|
{ PREF_CURSOR_FORE_COLOR, "255, 255, 255" },
|
||||||
|
{ PREF_CURSOR_BACK_COLOR, " 0, 0, 0" },
|
||||||
|
|
||||||
|
{ PREF_IM_FORE_COLOR, " 0, 0, 0" },
|
||||||
|
{ PREF_IM_BACK_COLOR, "152, 203, 255" },
|
||||||
|
{ PREF_IM_SELECT_COLOR, "255, 152, 152" },
|
||||||
|
|
||||||
|
{ PREF_SHELL, "/bin/sh -login" },
|
||||||
|
{ PREF_HISTORY_SIZE, "500" },
|
||||||
|
|
||||||
|
{ PREF_TEXT_ENCODING, "UTF-8" },
|
||||||
|
|
||||||
|
{ PREF_SELECT_MBUTTON, "Button 1"},
|
||||||
|
{ PREF_PASTE_MBUTTON, "Button 2"},
|
||||||
|
{ PREF_SUBMENU_MBUTTON, "Button 3"},
|
||||||
|
{ PREF_MOUSE_IMAGE, "Hand cursor"},
|
||||||
|
{ PREF_DRAGN_COPY, "0"},
|
||||||
|
|
||||||
|
{ PREF_GUI_LANGUAGE, "English"},
|
||||||
|
{ PREF_IM_AWARE, "0"},
|
||||||
|
{ NULL, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -47,6 +88,7 @@
|
|||||||
PrefHandler::PrefHandler()
|
PrefHandler::PrefHandler()
|
||||||
{
|
{
|
||||||
mPrefContainer.what = 'Pref';
|
mPrefContainer.what = 'Pref';
|
||||||
|
OpenText(TERM_PREF, termDefaults);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -155,12 +197,11 @@ PrefHandler::getString(const char *key)
|
|||||||
{
|
{
|
||||||
const char *buf;
|
const char *buf;
|
||||||
|
|
||||||
buf = mPrefContainer.FindString(key);
|
if (mPrefContainer.FindString(key, &buf) != B_OK)
|
||||||
if (buf == NULL)
|
|
||||||
buf = "Error!";
|
buf = "Error!";
|
||||||
|
|
||||||
|
//printf("%x GET %s: %s\n", this, key, buf);
|
||||||
return buf;
|
return buf;
|
||||||
|
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -232,6 +273,7 @@ PrefHandler::setBool(const char *key, bool data)
|
|||||||
void
|
void
|
||||||
PrefHandler::setString(const char *key, const char *data)
|
PrefHandler::setString(const char *key, const char *data)
|
||||||
{
|
{
|
||||||
|
//printf("%x SET %s: %s\n", this, key, data);
|
||||||
mPrefContainer.RemoveName(key);
|
mPrefContainer.RemoveName(key);
|
||||||
mPrefContainer.AddString(key, data);
|
mPrefContainer.AddString(key, data);
|
||||||
}
|
}
|
||||||
@@ -263,9 +305,40 @@ PrefHandler::IsEmpty() const
|
|||||||
status_t
|
status_t
|
||||||
PrefHandler::loadFromFile(BEntry *ent)
|
PrefHandler::loadFromFile(BEntry *ent)
|
||||||
{
|
{
|
||||||
|
// Future: It would be nice if we could simply use a flatened BMessage to
|
||||||
|
// save the settings. (Who cares about compatibility in this case anyway?)
|
||||||
|
|
||||||
BFile file (ent, B_READ_ONLY);
|
BFile file (ent, B_READ_ONLY);
|
||||||
mPrefContainer.MakeEmpty();
|
//mPrefContainer.MakeEmpty();
|
||||||
return mPrefContainer.Unflatten(&file);
|
//mPrefContainer.Unflatten(&file);
|
||||||
|
off_t size;
|
||||||
|
if (file.GetSize(&size) != B_OK || size != sizeof(struct termprefs))
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
struct termprefs prefs;
|
||||||
|
file.Read(&prefs, size);
|
||||||
|
if (prefs.magic != TP_MAGIC || prefs.version != TP_VERSION)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
//Valid settings file!
|
||||||
|
setInt32(PREF_COLS, prefs.cols);
|
||||||
|
setInt32(PREF_ROWS, prefs.rows);
|
||||||
|
setInt32(PREF_HALF_FONT_SIZE, prefs.font_size);
|
||||||
|
setInt32(PREF_FULL_FONT_SIZE, prefs.font_size);
|
||||||
|
char *font_family = strtok(prefs.font, "/");
|
||||||
|
char *font_style = strtok(NULL, "");
|
||||||
|
setString(PREF_FULL_FONT_FAMILY, font_family);
|
||||||
|
setString(PREF_FULL_FONT_STYLE, font_style);
|
||||||
|
setString(PREF_HALF_FONT_FAMILY, font_family);
|
||||||
|
setString(PREF_HALF_FONT_STYLE, font_style);
|
||||||
|
setRGB(PREF_TEXT_BACK_COLOR, prefs.bg);
|
||||||
|
setRGB(PREF_TEXT_FORE_COLOR, prefs.fg);
|
||||||
|
setRGB(PREF_CURSOR_BACK_COLOR, prefs.curbg);
|
||||||
|
setRGB(PREF_CURSOR_FORE_COLOR, prefs.curfg);
|
||||||
|
setRGB(PREF_SELECT_BACK_COLOR, prefs.selbg);
|
||||||
|
setRGB(PREF_SELECT_FORE_COLOR, prefs.selfg);
|
||||||
|
setString(PREF_TEXT_ENCODING, encoding_table[prefs.encoding].name);
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -35,6 +35,32 @@
|
|||||||
#include <GraphicsDefs.h>
|
#include <GraphicsDefs.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
|
||||||
|
#define TP_MAGIC 0xf1f2f3f4
|
||||||
|
#define TP_VERSION 0x02
|
||||||
|
#define TP_FONT_NAME_SZ 128
|
||||||
|
|
||||||
|
struct termprefs {
|
||||||
|
uint32 magic;
|
||||||
|
uint32 version;
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
uint32 cols;
|
||||||
|
uint32 rows;
|
||||||
|
uint32 tab_width;
|
||||||
|
uint32 font_size;
|
||||||
|
char font[TP_FONT_NAME_SZ]; // "Family/Style"
|
||||||
|
uint32 cursor_blink_rate; // blinktime in µs = 1000000
|
||||||
|
uint32 refresh_rate; // ??? = 0
|
||||||
|
rgb_color bg;
|
||||||
|
rgb_color fg;
|
||||||
|
rgb_color curbg;
|
||||||
|
rgb_color curfg;
|
||||||
|
rgb_color selbg;
|
||||||
|
rgb_color selfg;
|
||||||
|
char encoding; // index in the menu (0 = UTF-8)
|
||||||
|
char unknown[3];
|
||||||
|
};
|
||||||
|
|
||||||
struct prefDefaults
|
struct prefDefaults
|
||||||
{
|
{
|
||||||
const char *key;
|
const char *key;
|
||||||
|
|||||||
@@ -102,44 +102,6 @@ TermApp::~TermApp (void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Startup preference settings.
|
|
||||||
*/
|
|
||||||
const prefDefaults termDefaults[] ={
|
|
||||||
{ PREF_COLS, "80" },
|
|
||||||
{ PREF_ROWS, "25" },
|
|
||||||
|
|
||||||
{ PREF_HALF_FONT_FAMILY, "Courier10 BT" },
|
|
||||||
{ PREF_HALF_FONT_SIZE, "12" },
|
|
||||||
{ PREF_FULL_FONT_FAMILY, "Haru Tohaba" },
|
|
||||||
{ PREF_FULL_FONT_SIZE, "12" },
|
|
||||||
|
|
||||||
{ PREF_TEXT_FORE_COLOR, " 0, 0, 0" },
|
|
||||||
{ PREF_TEXT_BACK_COLOR, "255, 255, 255" },
|
|
||||||
{ PREF_SELECT_FORE_COLOR, "255, 255, 255" },
|
|
||||||
{ PREF_SELECT_BACK_COLOR, " 0, 0, 0" },
|
|
||||||
{ PREF_CURSOR_FORE_COLOR, "255, 255, 255" },
|
|
||||||
{ PREF_CURSOR_BACK_COLOR, " 0, 0, 0" },
|
|
||||||
|
|
||||||
{ PREF_IM_FORE_COLOR, " 0, 0, 0" },
|
|
||||||
{ PREF_IM_BACK_COLOR, "152, 203, 255" },
|
|
||||||
{ PREF_IM_SELECT_COLOR, "255, 152, 152" },
|
|
||||||
|
|
||||||
{ PREF_SHELL, "/bin/sh -login" },
|
|
||||||
{ PREF_HISTORY_SIZE, "500" },
|
|
||||||
|
|
||||||
{ PREF_TEXT_ENCODING, "UTF-8" },
|
|
||||||
|
|
||||||
{ PREF_SELECT_MBUTTON, "Button 1"},
|
|
||||||
{ PREF_PASTE_MBUTTON, "Button 2"},
|
|
||||||
{ PREF_SUBMENU_MBUTTON, "Button 3"},
|
|
||||||
{ PREF_MOUSE_IMAGE, "Hand cursor"},
|
|
||||||
{ PREF_DRAGN_COPY, "0"},
|
|
||||||
|
|
||||||
{ PREF_GUI_LANGUAGE, "English"},
|
|
||||||
{ PREF_IM_AWARE, "0"},
|
|
||||||
{ NULL, NULL},
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -155,11 +117,6 @@ TermApp::ReadyToRun (void)
|
|||||||
const char *encoding;
|
const char *encoding;
|
||||||
int rows, cols;
|
int rows, cols;
|
||||||
|
|
||||||
// gTermPref is not empty when App opened by pref file
|
|
||||||
if (gTermPref->IsEmpty()){
|
|
||||||
gTermPref->OpenText(TERM_PREF, termDefaults);
|
|
||||||
}
|
|
||||||
|
|
||||||
encoding = gTermPref->getString (PREF_TEXT_ENCODING);
|
encoding = gTermPref->getString (PREF_TEXT_ENCODING);
|
||||||
|
|
||||||
/* Get encoding name (setenv TTYPE in spawn_shell functions). */
|
/* Get encoding name (setenv TTYPE in spawn_shell functions). */
|
||||||
@@ -178,11 +135,6 @@ TermApp::ReadyToRun (void)
|
|||||||
command = gTermPref->getString (PREF_SHELL);
|
command = gTermPref->getString (PREF_SHELL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (geometry_requested) {
|
|
||||||
gTermPref->setInt32 (PREF_ROWS, fRows);
|
|
||||||
gTermPref->setInt32 (PREF_COLS, fCols);
|
|
||||||
}
|
|
||||||
|
|
||||||
rows = gTermPref->getInt32 (PREF_ROWS);
|
rows = gTermPref->getInt32 (PREF_ROWS);
|
||||||
cols = gTermPref->getInt32 (PREF_COLS);
|
cols = gTermPref->getInt32 (PREF_COLS);
|
||||||
|
|
||||||
@@ -303,7 +255,7 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
|
|
||||||
/* Load preference file. */
|
/* Load preference file. */
|
||||||
if (argmatch (argv, argc, "-p", "--preference", 4, &value, &skip_args)) {
|
if (argmatch (argv, argc, "-p", "--preference", 4, &value, &skip_args)) {
|
||||||
gTermPref->OpenText(value);
|
gTermPref->Open(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -325,8 +277,9 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
usage_requested = true;
|
usage_requested = true;
|
||||||
this->PostMessage (B_QUIT_REQUESTED);
|
this->PostMessage (B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
fCols = width;
|
gTermPref->setInt32 (PREF_COLS, width);
|
||||||
fRows = height;
|
gTermPref->setInt32 (PREF_ROWS, height);
|
||||||
|
|
||||||
fTermFrame.Set(xpos, ypos, xpos + 50, ypos + 50);
|
fTermFrame.Set(xpos, ypos, xpos + 50, ypos + 50);
|
||||||
geometry_requested = true;
|
geometry_requested = true;
|
||||||
}
|
}
|
||||||
@@ -355,12 +308,8 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
9, &value, &skip_args)) {
|
9, &value, &skip_args)) {
|
||||||
|
|
||||||
if (text_to_rgb (value, &color, buffer)) {
|
if (text_to_rgb (value, &color, buffer)) {
|
||||||
if (gTermPref->IsEmpty()){
|
|
||||||
gTermPref->OpenText(TERM_PREF, termDefaults);
|
|
||||||
}
|
|
||||||
gTermPref->setRGB (standard_args[i].prefname, color);
|
gTermPref->setRGB (standard_args[i].prefname, color);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
fprintf (stderr, "%s: invalid color string -- %s\n", argv[0], value);
|
fprintf (stderr, "%s: invalid color string -- %s\n", argv[0], value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@
|
|||||||
#include "ColorWindow.h"
|
#include "ColorWindow.h"
|
||||||
#include "AboutWindow.h"
|
#include "AboutWindow.h"
|
||||||
|
|
||||||
// Gloval Preference Handler
|
// Global Preference Handler
|
||||||
extern PrefHandler *gTermPref;
|
extern PrefHandler *gTermPref;
|
||||||
//
|
//
|
||||||
// help and GPL URL
|
// help and GPL URL
|
||||||
|
|||||||
Reference in New Issue
Block a user