Skip to content

Commit

Permalink
cˊoͣp‮‎p‏‪̌‮‎̌‏‪y‮‎y‏‪̀ t̊ěxˎt̅ t̀ò c̀lˊǐṕb̀oˊǎr˔dͪ iˇňs˕t˒e̙aˊ…
Browse files Browse the repository at this point in the history
…dͣ ơf̀ wˍr̀iˊtͣiͣn˕gː t̀ò fˎi˒l̂eˎ
  • Loading branch information
GlennFolker committed Nov 2, 2020
1 parent 104b887 commit 1ea735b
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/namegen/NameGen.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package namegen;

import namegen.Log.*;
import java.awt.*;
import java.awt.datatransfer.*;
import java.io.*;
import java.nio.charset.*;

public class NameGen{
private static boolean exit = false;
private static File file = new File("name.txt");

public static synchronized void main(String[] args){
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Expand Down Expand Up @@ -100,14 +100,26 @@ public static synchronized void name(BufferedReader reader) throws IOException{
}
}

try(
FileOutputStream output = new FileOutputStream(file, false);
OutputStreamWriter writer = new OutputStreamWriter(output, StandardCharsets.UTF_16);
){
writer.write(name);
writer.flush();
}finally{
Log.log(LogLevel.info, "Generated name is in: @!", file.getAbsolutePath());
boolean success = setClipboardString(result.toString());
if(success){
Log.log(LogLevel.info, "Generated name has been copied to clipboard!");
}else{
Log.log(LogLevel.warn, "Couldn't copy the generated name to clipboard!");
}
}

public static synchronized boolean setClipboardString(String contents){
try{
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection data = new StringSelection(contents);

clipboard.setContents(data, data);

return true;
}catch(Exception e){
Log.log(LogLevel.error, null, e);

return false;
}
}
}

0 comments on commit 1ea735b

Please sign in to comment.