12
12
import java .util .ArrayList ;
13
13
import java .util .Arrays ;
14
14
import java .util .List ;
15
- import org .jline .reader .LineReader ;
16
- import org .jline .reader .LineReaderBuilder ;
17
- import org .jline .reader .EndOfFileException ;
18
- import org .jline .reader .UserInterruptException ;
19
- import org .jline .terminal .Terminal ;
20
- import org .jline .terminal .TerminalBuilder ;
21
15
22
16
import static org .perlonjava .Configuration .getPerlVersionBundle ;
23
17
import static org .perlonjava .Configuration .perlVersion ;
@@ -46,58 +40,27 @@ public static CompilerOptions parseArguments(String[] args) {
46
40
// If no code was provided and no filename, try reading from stdin
47
41
if (parsedArgs .code == null ) {
48
42
try {
43
+ // Try to read from stdin - this will work for pipes, redirections, and interactive input
49
44
StringBuilder stdinContent = new StringBuilder ();
45
+ BufferedReader reader = new BufferedReader (new InputStreamReader (System .in ));
46
+
47
+ // Check if we're reading from a pipe/redirection vs interactive terminal
50
48
boolean isInteractive = System .console () != null ;
51
49
52
50
if (isInteractive ) {
53
- // Interactive mode with JLine for better editing experience
54
- try {
55
- Terminal terminal = TerminalBuilder .builder ()
56
- .system (true )
57
- .build ();
58
-
59
- LineReader lineReader = LineReaderBuilder .builder ()
60
- .terminal (terminal )
61
- .build ();
62
-
63
- System .err .println ("Enter Perl code (press Ctrl+D when done, or type 'exit' to quit):" );
64
- System .err .println ("Use arrow keys to navigate, Ctrl+A/E for home/end" );
65
-
66
- String line ;
67
- while (true ) {
68
- try {
69
- line = lineReader .readLine ("> " );
70
- if (line != null ) {
71
- if ("exit" .equals (line .trim ())) {
72
- break ;
73
- }
74
- stdinContent .append (line ).append ("\n " );
75
- }
76
- } catch (EndOfFileException e ) {
77
- // User pressed Ctrl+D
78
- break ;
79
- } catch (UserInterruptException e ) {
80
- // User pressed Ctrl+C
81
- System .err .println ("\n Interrupted. Use 'exit' or Ctrl+D to quit." );
82
- break ;
83
- }
84
- }
51
+ // Interactive mode - prompt the user and read until EOF (Ctrl+D)
52
+ System .err .println ("Enter Perl code (press Ctrl+D when done):" );
53
+ }
85
54
86
- terminal .close ();
87
- } catch (Exception e ) {
88
- // Fall back to basic readline if JLine fails
89
- System .err .println ("Enhanced editing not available, falling back to basic mode." );
90
- System .err .println ("Enter Perl code (press Ctrl+D when done):" );
91
- fallbackReadlines (stdinContent );
92
- }
93
- } else {
94
- // Non-interactive mode (pipes, redirections)
95
- fallbackReadlines (stdinContent );
55
+ // Read from stdin regardless of whether it's interactive or not
56
+ String line ;
57
+ while ((line = reader .readLine ()) != null ) {
58
+ stdinContent .append (line ).append ("\n " );
96
59
}
97
60
98
61
if (stdinContent .length () > 0 ) {
99
62
parsedArgs .code = stdinContent .toString ();
100
- parsedArgs .fileName = "-" ;
63
+ parsedArgs .fileName = "-" ; // Indicate that code came from stdin
101
64
}
102
65
} catch (IOException e ) {
103
66
// If we can't read from stdin, continue with normal error handling
@@ -109,14 +72,6 @@ public static CompilerOptions parseArguments(String[] args) {
109
72
return parsedArgs ;
110
73
}
111
74
112
- private static void fallbackReadlines (StringBuilder stdinContent ) throws IOException {
113
- BufferedReader reader = new BufferedReader (new InputStreamReader (System .in ));
114
- String line ;
115
- while ((line = reader .readLine ()) != null ) {
116
- stdinContent .append (line ).append ("\n " );
117
- }
118
- }
119
-
120
75
/**
121
76
* Processes the command-line arguments, distinguishing between switch and non-switch arguments.
122
77
*
0 commit comments