1 package be
.nikiroo
.jvcard
.tui
;
4 import java
.io
.IOException
;
5 import java
.lang
.reflect
.Field
;
6 import java
.nio
.charset
.Charset
;
7 import java
.util
.LinkedList
;
10 import be
.nikiroo
.jvcard
.i18n
.Trans
;
11 import be
.nikiroo
.jvcard
.i18n
.Trans
.StringId
;
12 import be
.nikiroo
.jvcard
.tui
.panes
.FileList
;
14 import com
.googlecode
.lanterna
.gui2
.Window
;
15 import com
.googlecode
.lanterna
.input
.KeyStroke
;
18 * This class contains the runnable Main method. It will parse the user supplied
19 * parameters and take action based upon those. Most of the time, it will start
26 public static final String APPLICATION_TITLE
= "jVcard";
27 public static final String APPLICATION_VERSION
= "1.0-beta2-dev";
29 static private Trans transService
;
32 * Translate the given {@link StringId}.
37 * @return the translation
39 static public String
trans(StringId id
) {
40 if (transService
== null)
43 return transService
.trans(id
);
47 * Translate the given {@link KeyStroke}.
50 * the key to translate
52 * @return the translation
54 static public String
trans(KeyStroke key
) {
55 if (transService
== null)
58 return transService
.trans(key
);
62 * Start the application.
65 * the parameters (see --help to know hich are supported)
67 public static void main(String
[] args
) {
68 Boolean textMode
= null;
69 boolean noMoreParams
= false;
70 boolean filesTried
= false;
72 // get the "system default" language to help translate the --help
74 String language
= null;
75 transService
= new Trans(null);
77 List
<File
> files
= new LinkedList
<File
>();
78 for (int index
= 0; index
< args
.length
; index
++) {
79 String arg
= args
[index
];
80 if (!noMoreParams
&& arg
.equals("--")) {
82 } else if (!noMoreParams
&& arg
.equals("--help")) {
84 .println("TODO: implement some help text.\n"
85 + "Usable switches:\n"
86 + "\t--: stop looking for switches\n"
87 + "\t--help: this here thingy\n"
88 + "\t--lang LANGUAGE: choose the language, for instance en_GB\n"
89 + "\t--tui: force pure text mode even if swing treminal is available\n"
90 + "\t--gui: force swing terminal mode\n"
91 + "\t--noutf: force non-utf8 mode if you need it\n"
92 + "\t--noutfa: force non-utf8 and no accents mode if you need it\n"
93 + "everyhing else is either a file to open or a directory to open\n"
94 + "(we will only open 1st level files in given directories)");
96 } else if (!noMoreParams
&& arg
.equals("--tui")) {
98 } else if (!noMoreParams
&& arg
.equals("--gui")) {
100 } else if (!noMoreParams
&& arg
.equals("--noutf")) {
101 UiColors
.getInstance().setUnicode(false);
102 } else if (!noMoreParams
&& arg
.equals("--lang")) {
104 if (index
< args
.length
)
105 language
= args
[index
];
106 transService
= new Trans(language
);
109 files
.addAll(open(arg
));
113 if (UiColors
.getInstance().isUnicode()) {
117 if (files
.size() == 0) {
123 files
.addAll(open("."));
126 Window win
= new MainWindow(new FileList(files
));
129 TuiLauncher
.start(textMode
, win
);
130 } catch (IOException ioe
) {
131 ioe
.printStackTrace();
137 * Open the given path and add all its files if it is a directory or just
138 * this one if not to the returned list.
143 * @return the list of opened files
145 static private List
<File
> open(String path
) {
146 List
<File
> files
= new LinkedList
<File
>();
148 File file
= new File(path
);
150 if (file
.isDirectory()) {
151 for (File subfile
: file
.listFiles()) {
152 if (!subfile
.isDirectory())
159 System
.err
.println("File or directory not found: \"" + path
+ "\"");
166 * Really, really ask for UTF-8 encoding.
168 static private void utf8() {
170 System
.setProperty("file.encoding", "UTF-8");
171 Field charset
= Charset
.class.getDeclaredField("defaultCharset");
172 charset
.setAccessible(true);
173 charset
.set(null, null);
174 } catch (SecurityException
| NoSuchFieldException
175 | IllegalArgumentException
| IllegalAccessException e
) {